Package test_suite :: Package system_tests :: Module relax_disp
[hide private]
[frames] | no frames]

Source Code for Module test_suite.system_tests.relax_disp

   1  ############################################################################### 
   2  #                                                                             # 
   3  # Copyright (C) 2006-2014 Edward d'Auvergne                                   # 
   4  # Copyright (C) 2009 Sebastien Morin                                          # 
   5  # Copyright (C) 2013-2014 Troels E. Linnet                                    # 
   6  #                                                                             # 
   7  # This file is part of the program relax (http://www.nmr-relax.com).          # 
   8  #                                                                             # 
   9  # This program is free software: you can redistribute it and/or modify        # 
  10  # it under the terms of the GNU General Public License as published by        # 
  11  # the Free Software Foundation, either version 3 of the License, or           # 
  12  # (at your option) any later version.                                         # 
  13  #                                                                             # 
  14  # This program is distributed in the hope that it will be useful,             # 
  15  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
  16  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
  17  # GNU General Public License for more details.                                # 
  18  #                                                                             # 
  19  # You should have received a copy of the GNU General Public License           # 
  20  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
  21  #                                                                             # 
  22  ############################################################################### 
  23   
  24  # Python module imports. 
  25  from os import F_OK, access, getcwd, path, sep 
  26  from numpy import array, asarray, exp, median, inf, log, save, std, sum, zeros 
  27  from minfx.generic import generic_minimise 
  28  from random import gauss 
  29  import re, math 
  30  from tempfile import mkdtemp, NamedTemporaryFile 
  31   
  32   
  33  # relax module imports. 
  34  from auto_analyses import relax_disp 
  35  from data_store import Relax_data_store; ds = Relax_data_store() 
  36  import dep_check 
  37  from lib.errors import RelaxError 
  38  from lib.io import get_file_path 
  39  from pipe_control.mol_res_spin import generate_spin_string, return_spin, spin_loop 
  40  from pipe_control.minimise import assemble_scaling_matrix 
  41  from specific_analyses.relax_disp.checks import check_missing_r1 
  42  from specific_analyses.relax_disp.estimate_r2eff import estimate_r2eff 
  43  from specific_analyses.relax_disp.data import average_intensity, check_intensity_errors, generate_r20_key, get_curve_type, has_exponential_exp_type, has_r1rho_exp_type, loop_exp_frq, loop_exp_frq_offset_point, loop_exp_frq_offset_point_time, loop_time, return_grace_file_name_ini, return_param_key_from_data, spin_ids_to_containers 
  44  from specific_analyses.relax_disp.data import INTERPOLATE_DISP, INTERPOLATE_OFFSET, X_AXIS_DISP, X_AXIS_W_EFF, X_AXIS_THETA, Y_AXIS_R2_R1RHO, Y_AXIS_R2_EFF 
  45  from specific_analyses.relax_disp.model import models_info, nesting_param 
  46  from specific_analyses.relax_disp.parameters import linear_constraints 
  47  from specific_analyses.relax_disp.variables import EXP_TYPE_CPMG_DQ, EXP_TYPE_CPMG_MQ, EXP_TYPE_CPMG_PROTON_MQ, EXP_TYPE_CPMG_PROTON_SQ, EXP_TYPE_CPMG_SQ, EXP_TYPE_CPMG_ZQ, EXP_TYPE_LIST, EXP_TYPE_R1RHO, MODEL_B14_FULL, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, MODEL_IT99, MODEL_LIST_ANALYTIC_CPMG, MODEL_LIST_FULL, MODEL_LIST_NUMERIC_CPMG, MODEL_LM63, MODEL_M61, MODEL_M61B, MODEL_MP05, MODEL_NOREX, MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_NS_CPMG_2SITE_STAR_FULL, MODEL_NS_R1RHO_2SITE, MODEL_NS_R1RHO_3SITE, MODEL_NS_R1RHO_3SITE_LINEAR, MODEL_PARAMS, MODEL_R2EFF, MODEL_TP02, MODEL_TAP03 
  48  from status import Status; status = Status() 
  49  from test_suite.system_tests.base_classes import SystemTestCase 
  50   
  51  # C modules. 
  52  if dep_check.C_module_exp_fn: 
  53      from specific_analyses.relax_fit.optimisation import func_wrapper, dfunc_wrapper, d2func_wrapper 
  54      from target_functions.relax_fit import jacobian, jacobian_chi2, setup 
  55      # Call the python wrapper function to help with list to numpy array conversion. 
  56      func = func_wrapper 
  57      dfunc = dfunc_wrapper 
  58      d2func = d2func_wrapper 
  59   
  60   
61 -class Relax_disp(SystemTestCase):
62 """Class for testing various aspects specific to relaxation dispersion curve-fitting.""" 63
64 - def __init__(self, methodName='runTest'):
65 """Skip certain tests if the C modules are non-functional. 66 67 @keyword methodName: The name of the test. 68 @type methodName: str 69 """ 70 71 # Execute the base class method. 72 super(Relax_disp, self).__init__(methodName) 73 74 # Missing module. 75 if not dep_check.C_module_exp_fn: 76 # The list of tests to skip. 77 to_skip = [ 78 "test_bug_atul_srivastava", 79 "test_bug_21344_sparse_time_spinlock_acquired_r1rho_fail_relax_disp", 80 "test_bug_9999_slow_r1rho_r2eff_error_with_mc", 81 "test_estimate_r2eff_err", 82 "test_estimate_r2eff_err_auto", 83 "test_estimate_r2eff_err_methods", 84 "test_finite_value", 85 "test_exp_fit", 86 "test_m61_exp_data_to_m61", 87 "test_r1rho_kjaergaard_auto", 88 "test_r1rho_kjaergaard_auto_check_graphs", 89 "test_r1rho_kjaergaard_man", 90 "test_r1rho_kjaergaard_missing_r1", 91 "test_value_write_calc_rotating_frame_params_auto_analysis" 92 ] 93 94 # Store in the status object. 95 if methodName in to_skip: 96 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type]) 97 98 # If not scipy.optimize.leastsq. 99 if not dep_check.scipy_module: 100 # The list of tests to skip. 101 to_skip = [ 102 "test_estimate_r2eff_err_methods" 103 ] 104 105 # Store in the status object. 106 if methodName in to_skip: 107 status.skipped_tests.append([methodName, 'scipy.optimize.leastsq module', self._skip_type])
108 109
110 - def setUp(self):
111 """Set up for all the functional tests.""" 112 113 # Create the data pipe. 114 self.interpreter.pipe.create('relax_disp', 'relax_disp') 115 116 # Create a temporary directory for dumping files. 117 ds.tmpdir = mkdtemp() 118 self.tmpdir = ds.tmpdir
119 120
121 - def setup_bug_22146_unpacking_r2a_r2b_cluster(self, folder=None, model_analyse=None, places = 7):
122 """Setup data for the catch of U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered full dispersion models. 123 124 @keyword folder: The name of the folder for the test data. 125 @type folder: str 126 @keyword model_analyse: The name of the model which will be tested. 127 @type model_analyse: str 128 """ 129 130 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 131 132 # Data. 133 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22146_unpacking_r2a_r2b_cluster'+sep+folder 134 135 ## Experiments 136 # Exp 1 137 sfrq_1 = 500.0*1E6 138 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 139 time_T2_1 = 0.05 140 ncycs_1 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 50] 141 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 142 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 143 r2eff_errs_1 = [0.0] * len(ncycs_1) 144 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 145 146 sfrq_2 = 600.0*1E6 147 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 148 time_T2_2 = 0.06 149 ncycs_2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 60] 150 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 151 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 152 r2eff_errs_2 = [0.0] * len(ncycs_2) 153 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 154 155 sfrq_3 = 700.0*1E6 156 r20_key_3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_3) 157 time_T2_3 = 0.07 158 ncycs_3 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 50, 70] 159 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 160 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 161 r2eff_errs_3 = [0.0] * len(ncycs_3) 162 exp_3 = [sfrq_3, time_T2_3, ncycs_3, r2eff_errs_3] 163 164 # Collect all exps 165 exps = [exp_1, exp_2, exp_3] 166 167 R20 = [5.1, 5.2, 5.3, 10.1, 10.2, 10.3, 6.1, 6.2, 6.3, 11.1, 11.2, 11.3, 7.1, 7.2, 7.3, 12.1, 12.2, 12.3, 8.1, 8.2, 8.3, 13.1, 13.2, 13.3] 168 dw_arr = [1.0, 2.0, 3.0, 4.0] 169 pA_arr = [0.9] 170 kex_arr = [1000.] 171 172 spins = [ 173 ['Ala', 1, 'N', {'r2a': {r20_key_1: R20[0], r20_key_2: R20[1], r20_key_3: R20[2]}, 'r2b': {r20_key_1: R20[3], r20_key_2: R20[4], r20_key_3: R20[5]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[0]}], 174 ['Ala', 2, 'N', {'r2a': {r20_key_1: R20[6], r20_key_2: R20[7], r20_key_3: R20[8]}, 'r2b': {r20_key_1: R20[9], r20_key_2: R20[10], r20_key_3: R20[11]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[1]}], 175 ['Ala', 3, 'N', {'r2a': {r20_key_1: R20[12], r20_key_2: R20[13], r20_key_3: R20[14]}, 'r2b': {r20_key_1: R20[15], r20_key_2: R20[16], r20_key_3: R20[17]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[2]}], 176 ['Ala', 4, 'N', {'r2a': {r20_key_1: R20[18], r20_key_2: R20[19], r20_key_3: R20[20]}, 'r2b': {r20_key_1: R20[21], r20_key_2: R20[22], r20_key_3: R20[23]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[3]}], 177 ] 178 179 # Create the data pipe. 180 pipe_name = 'base pipe' 181 pipe_type = 'relax_disp' 182 pipe_bundle = 'relax_disp' 183 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type, bundle = pipe_bundle) 184 185 # Generate the sequence. 186 for res_name, res_num, spin_name, params in spins: 187 self.interpreter.spin.create(res_name=res_name, res_num=res_num, spin_name=spin_name) 188 189 # Set isotope 190 self.interpreter.spin.isotope('15N', spin_id='@N') 191 192 # Now loop over the experiments, to set the variables in relax. 193 exp_ids = [] 194 for exp_i in exps: 195 sfrq, time_T2, ncycs, r2eff_errs = exp_i 196 exp_id = 'CPMG_%3.1f' % (sfrq/1E6) 197 exp_ids.append(exp_id) 198 199 ids = [] 200 for ncyc in ncycs: 201 nu_cpmg = ncyc / time_T2 202 cur_id = '%s_%.1f' % (exp_id, nu_cpmg) 203 ids.append(cur_id) 204 205 # Set the spectrometer frequency. 206 self.interpreter.spectrometer.frequency(id=cur_id, frq=sfrq) 207 208 # Set the experiment type. 209 self.interpreter.relax_disp.exp_type(spectrum_id=cur_id, exp_type=EXP_TYPE_CPMG_SQ) 210 211 # Set the relaxation dispersion CPMG constant time delay T (in s). 212 self.interpreter.relax_disp.relax_time(spectrum_id=cur_id, time=time_T2) 213 214 # Set the relaxation dispersion CPMG frequencies. 215 self.interpreter.relax_disp.cpmg_setup(spectrum_id=cur_id, cpmg_frq=nu_cpmg) 216 217 print("\n\nThe experiment IDs are %s." % cdp.spectrum_ids) 218 219 ### Now do fitting. 220 # Change pipe. 221 222 pipe_name_MODEL = "%s_%s"%(pipe_name, model_analyse) 223 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_MODEL, bundle_to = pipe_bundle) 224 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 225 226 # Now read data in. 227 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 228 exp_id = exp_ids[mi] 229 exp_i = exps[mi] 230 sfrq, time_T2, ncycs, r2eff_errs = exp_i 231 232 # Then loop over the spins. 233 for res_name, res_num, spin_name, params in spins: 234 cur_spin_id = ":%i@%s"%(res_num, spin_name) 235 236 # Define file name 237 file_name = "%s%s.txt" % (exp_id, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 238 239 # Read in the R2eff file to put into spin structure. 240 self.interpreter.relax_disp.r2eff_read_spin(id=exp_id, spin_id=cur_spin_id, file=file_name, dir=data_path, disp_point_col=1, data_col=2, error_col=3) 241 242 # Then select model. 243 self.interpreter.relax_disp.select_model(model=model_analyse) 244 245 # Then cluster 246 self.interpreter.relax_disp.cluster('model_cluster', ":1-100") 247 248 # Grid search 249 low_arr = R20 + dw_arr + pA_arr + kex_arr 250 self.interpreter.minimise.grid_search(lower=low_arr, upper=low_arr, inc=1, constraints=True, verbosity=1) 251 252 # Then loop over the defined spins and read the parameters. 253 for i in range(len(spins)): 254 res_name, res_num, spin_name, params = spins[i] 255 cur_spin_id = ":%i@%s"%(res_num, spin_name) 256 cur_spin = return_spin(cur_spin_id) 257 258 for mo_param in cur_spin.params: 259 print(mo_param) 260 # The R2 is a dictionary, depending on spectrometer frequency. 261 if isinstance(getattr(cur_spin, mo_param), dict): 262 for key, val in getattr(cur_spin, mo_param).items(): 263 should_be = params[mo_param][key] 264 print(cur_spin.model, res_name, cur_spin_id, mo_param, key, float(val), should_be) 265 self.assertAlmostEqual(val, should_be) 266 else: 267 should_be = float(params[mo_param]) 268 val = getattr(cur_spin, mo_param) 269 print(cur_spin.model, res_name, cur_spin_id, mo_param, val, should_be) 270 self.assertAlmostEqual(val, should_be) 271 272 # Test chi2. 273 # At this point the chi-squared value at the solution should be zero, as the relaxation data was created with the same parameter values. 274 self.assertAlmostEqual(cur_spin.chi2, 0.0, places = places)
275 276
277 - def setup_r1rho_kjaergaard(self, cluster_ids=[], read_R1=True):
278 """Set up the data for the test_r1rho_kjaergaard_*() system tests.""" 279 280 # The path to the data files. 281 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 282 283 # Set pipe name, bundle and type. 284 ds.pipe_name = 'base pipe' 285 ds.pipe_bundle = 'relax_disp' 286 ds.pipe_type = 'relax_disp' 287 288 # Create the data pipe. 289 self.interpreter.pipe.create(pipe_name=ds.pipe_name, bundle=ds.pipe_bundle, pipe_type=ds.pipe_type) 290 291 # Read the spins. 292 self.interpreter.spectrum.read_spins(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 293 294 # Name the isotope for field strength scaling. 295 self.interpreter.spin.isotope(isotope='15N') 296 297 # Set number of experiments to be used. 298 NR_exp = 70 299 300 # Load the experiments settings file. 301 expfile = open(data_path+sep+'exp_parameters_sort.txt', 'r') 302 expfileslines = expfile.readlines()[:NR_exp] 303 expfile.close() 304 305 # In MHz 306 yOBS = 81.050 307 # In ppm 308 yCAR = 118.078 309 centerPPM_N15 = yCAR 310 311 ## Read the chemical shift data. 312 self.interpreter.chemical_shift.read(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 313 314 # The lock power to field, has been found in an calibration experiment. 315 spin_lock_field_strengths_Hz = {'35': 431.0, '39': 651.2, '41': 800.5, '43': 984.0, '46': 1341.11, '48': 1648.5} 316 317 # Apply spectra settings. 318 # Count settings 319 j = 0 320 for i in range(len(expfileslines)): 321 line = expfileslines[i] 322 if line[0] == "#": 323 continue 324 else: 325 # DIRN I deltadof2 dpwr2slock ncyc trim ss sfrq 326 DIRN = line.split()[0] 327 I = int(line.split()[1]) 328 deltadof2 = line.split()[2] 329 dpwr2slock = line.split()[3] 330 ncyc = int(line.split()[4]) 331 trim = float(line.split()[5]) 332 ss = int(line.split()[6]) 333 set_sfrq = float(line.split()[7]) 334 apod_rmsd = float(line.split()[8]) 335 spin_lock_field_strength = spin_lock_field_strengths_Hz[dpwr2slock] 336 337 # Calculate spin_lock time 338 time_sl = 2*ncyc*trim 339 340 # Define file name for peak list. 341 FNAME = "%s_%s_%s_%s_max_standard.ser"%(I, deltadof2, dpwr2slock, ncyc) 342 sp_id = "%s_%s_%s_%s"%(I, deltadof2, dpwr2slock, ncyc) 343 344 # Load the peak intensities. 345 self.interpreter.spectrum.read_intensities(file=FNAME, dir=data_path+sep+'peak_lists', spectrum_id=sp_id, int_method='height') 346 347 # Set the peak intensity errors, as defined as the baseplane RMSD. 348 self.interpreter.spectrum.baseplane_rmsd(error=apod_rmsd, spectrum_id=sp_id) 349 350 # Set the relaxation dispersion experiment type. 351 self.interpreter.relax_disp.exp_type(spectrum_id=sp_id, exp_type='R1rho') 352 353 # Set The spin-lock field strength, nu1, in Hz 354 self.interpreter.relax_disp.spin_lock_field(spectrum_id=sp_id, field=spin_lock_field_strength) 355 356 # Calculating the spin-lock offset in ppm, from offsets values provided in Hz. 357 frq_N15_Hz = yOBS * 1E6 358 offset_ppm_N15 = float(deltadof2) / frq_N15_Hz * 1E6 359 omega_rf_ppm = centerPPM_N15 + offset_ppm_N15 360 361 # Set The spin-lock offset, omega_rf, in ppm. 362 self.interpreter.relax_disp.spin_lock_offset(spectrum_id=sp_id, offset=omega_rf_ppm) 363 364 # Set the relaxation times (in s). 365 self.interpreter.relax_disp.relax_time(spectrum_id=sp_id, time=time_sl) 366 367 # Set the spectrometer frequency. 368 self.interpreter.spectrometer.frequency(id=sp_id, frq=set_sfrq, units='MHz') 369 370 # Add to counter 371 j += 1 372 373 374 print("Testing the number of settings") 375 print("Number of settings iterations is: %s. Number of cdp.exp_type.keys() is: %s"%(i, len(cdp.exp_type.keys() ) ) ) 376 self.assertEqual(70, len(expfileslines)) 377 self.assertEqual(69, j) 378 self.assertEqual(69, len(cdp.exp_type.keys()) ) 379 380 # Cluster spins 381 for curspin in cluster_ids: 382 print("Adding spin %s to cluster"%curspin) 383 self.interpreter.relax_disp.cluster('model_cluster', curspin) 384 385 # De-select for analysis those spins who have not been clustered 386 for free_spin in cdp.clustering['free spins']: 387 print("Deselecting free spin %s"%free_spin) 388 self.interpreter.deselect.spin(spin_id=free_spin, change_all=False) 389 390 391 #Paper reference values 392 # Resi Resn R1_rad_s R1err_rad_s R2_rad_s R2err_rad_s kEX_rad_s kEXerr_rad_s phi_rad2_s2 phierr_rad2_s2 phi_ppm2 phierr_ppm2 393 # Scaling rad2_s2 to ppm2: scaling_rad2_s2 = frequency_to_ppm(frq=1/(2*pi), B0=cdp.spectrometer_frq_list[0], isotope='15N')**2 = 3.85167990165e-06 394 ds.ref = dict() 395 ds.ref[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 396 ds.ref[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 397 ds.ref[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 398 ds.ref[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 399 ds.ref[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 400 ds.ref[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 401 ds.ref[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 402 ds.ref[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 403 ds.ref[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 404 ds.ref[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 405 ds.ref[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 406 ds.ref[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 407 ds.ref[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 408 ds.ref[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 409 ds.ref[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 410 411 ds.guess = dict() 412 ds.guess[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 413 ds.guess[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 414 ds.guess[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 415 ds.guess[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 416 ds.guess[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 417 ds.guess[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 418 ds.guess[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 419 ds.guess[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 420 ds.guess[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 421 ds.guess[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 422 ds.guess[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 423 ds.guess[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 424 ds.guess[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 425 ds.guess[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 426 ds.guess[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 427 428 # Assign guess values. 429 for spin, spin_id in spin_loop(return_id=True): 430 if spin_id in cluster_ids: 431 print("spin_id %s in cluster ids"%(spin_id)) 432 spin.kex = ds.guess[spin_id][6] 433 spin.phi_ex = ds.guess[spin_id][10] 434 else: 435 print("spin_id %s NOT in cluster ids"%(spin_id)) 436 437 if read_R1: 438 # Read the R1 data 439 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7)
440 441
442 - def setup_hansen_cpmg_data(self, model=None):
443 """Set up the data for the test_hansen_cpmg_data_*() system tests. 444 445 @keyword model: The name of the model which will be tested. 446 @type model: str 447 """ 448 449 # Create the data pipe and load the base data. 450 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 451 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 452 self.interpreter.results.read(data_path+sep+'base_pipe') 453 self.interpreter.deselect.spin(':4') 454 455 # Set the nuclear isotope data. 456 self.interpreter.spin.isotope('15N') 457 458 # Create the R2eff data pipe and load the results. 459 self.interpreter.pipe.create(pipe_name='R2eff - relax_disp', pipe_type='relax_disp') 460 self.interpreter.pipe.switch(pipe_name='R2eff - relax_disp') 461 self.interpreter.results.read(data_path+sep+'r2eff_pipe') 462 self.interpreter.deselect.spin(':4') 463 464 # The model data pipe. 465 pipe_name = "%s - relax_disp" % model 466 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 467 self.interpreter.pipe.switch(pipe_name=pipe_name) 468 469 # Set the model. 470 self.interpreter.relax_disp.select_model(model=model) 471 472 # Copy the data. 473 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to=pipe_name, param='r2eff')
474 475
476 - def setup_kteilum_fmpoulsen_makke_cpmg_data(self, model=None, expfolder=None):
477 """Set up the data for the test_kteilum_fmpoulsen_makke_cpmg_data_*() system tests. 478 479 @keyword model: The name of the model which will be tested. 480 @type model: str 481 """ 482 483 # Create the data pipe and load the base data. 484 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder 485 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 486 self.interpreter.results.read(data_path+sep+'ini_setup_trunc') 487 488 # Create the R2eff data pipe and load the results. 489 self.interpreter.pipe.create(pipe_name='R2eff', pipe_type='relax_disp') 490 self.interpreter.pipe.switch(pipe_name='R2eff') 491 self.interpreter.results.read(data_path+sep+'r2eff_pipe_trunc') 492 493 # The model data pipe. 494 pipe_name = "%s - relax_disp" % model 495 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 496 self.interpreter.pipe.switch(pipe_name=pipe_name) 497 498 # Set the model. 499 self.interpreter.relax_disp.select_model(model=model) 500 501 # Copy the data. 502 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
503 504
505 - def setup_korzhnev_2005_data(self, data_list=[]):
506 """Set up the data for the test_korzhnev_2005_data_*() system tests using the 'NS MMQ 2-site' model. 507 508 This loads the proton-heteronuclear SQ, ZQ, DQ, and MQ (MMQ) data from: 509 510 - Dmitry M. Korzhnev, Philipp Neudecker, Anthony Mittermaier, Vladislav Yu. Orekhov, and Lewis E. Kay (2005) Multiple-site exchange in proteins studied with a suite of six NMR relaxation dispersion experiments: An application to the folding of a Fyn SH3 domain mutant. 127, 15602-15611 (U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}). 511 512 It consists of the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 513 514 515 @keyword data_list: The list of data to load. It can contain 'SQ', '1H SQ', 'ZQ', 'DQ', 'MQ', and '1H MQ'. 516 @type data_list: list of str 517 """ 518 519 # Create the data pipe and load the base data. 520 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 521 self.interpreter.pipe.create(pipe_name='Korzhnev et al., 2005', pipe_type='relax_disp') 522 523 # Create the spin system. 524 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 525 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 526 self.interpreter.spin.element('H', spin_id='@H') 527 self.interpreter.spin.element('N', spin_id='@N') 528 self.interpreter.spin.isotope('1H', spin_id='@H') 529 self.interpreter.spin.isotope('15N', spin_id='@N') 530 531 # Define the magnetic dipole-dipole relaxation interaction. 532 self.interpreter.interatom.define(spin_id1=':9@N', spin_id2=':9@H', direct_bond=True) 533 534 # The spectral data - experiment ID, R2eff file name, experiment type, spin ID string, spectrometer frequency in Hertz, relaxation time. 535 data = [ 536 ['1H SQ', '1H_SQ_CPMG_500_MHz', 'hs_500.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 500e6, 0.03], 537 ['1H SQ', '1H_SQ_CPMG_600_MHz', 'hs_600.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 600e6, 0.03], 538 ['1H SQ', '1H_SQ_CPMG_800_MHz', 'hs_800.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 800e6, 0.03], 539 ['SQ', '15N_SQ_CPMG_500_MHz', 'ns_500.res', EXP_TYPE_CPMG_SQ, ':9@N', 500e6, 0.04], 540 ['SQ', '15N_SQ_CPMG_600_MHz', 'ns_600.res', EXP_TYPE_CPMG_SQ, ':9@N', 600e6, 0.04], 541 ['SQ', '15N_SQ_CPMG_800_MHz', 'ns_800.res', EXP_TYPE_CPMG_SQ, ':9@N', 800e6, 0.04], 542 ['DQ', '15N_DQ_CPMG_500_MHz', 'dq_500.res', EXP_TYPE_CPMG_DQ, ':9@N', 500e6, 0.03], 543 ['DQ', '15N_DQ_CPMG_600_MHz', 'dq_600.res', EXP_TYPE_CPMG_DQ, ':9@N', 600e6, 0.03], 544 ['DQ', '15N_DQ_CPMG_800_MHz', 'dq_800.res', EXP_TYPE_CPMG_DQ, ':9@N', 800e6, 0.03], 545 ['ZQ', '15N_ZQ_CPMG_500_MHz', 'zq_500.res', EXP_TYPE_CPMG_ZQ, ':9@N', 500e6, 0.03], 546 ['ZQ', '15N_ZQ_CPMG_600_MHz', 'zq_600.res', EXP_TYPE_CPMG_ZQ, ':9@N', 600e6, 0.03], 547 ['ZQ', '15N_ZQ_CPMG_800_MHz', 'zq_800.res', EXP_TYPE_CPMG_ZQ, ':9@N', 800e6, 0.03], 548 ['1H MQ', '1H_MQ_CPMG_500_MHz', 'hm_500.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 500e6, 0.02], 549 ['1H MQ', '1H_MQ_CPMG_600_MHz', 'hm_600.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 600e6, 0.02], 550 ['1H MQ', '1H_MQ_CPMG_800_MHz', 'hm_800.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 800e6, 0.02], 551 ['MQ', '15N_MQ_CPMG_500_MHz', 'nm_500.res', EXP_TYPE_CPMG_MQ, ':9@N', 500e6, 0.02], 552 ['MQ', '15N_MQ_CPMG_600_MHz', 'nm_600.res', EXP_TYPE_CPMG_MQ, ':9@N', 600e6, 0.02], 553 ['MQ', '15N_MQ_CPMG_800_MHz', 'nm_800.res', EXP_TYPE_CPMG_MQ, ':9@N', 800e6, 0.02] 554 ] 555 cpmg_frqs_1h_sq = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 556 cpmg_frqs_sq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 557 cpmg_frqs_dq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 558 cpmg_frqs_zq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 559 cpmg_frqs_1h_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0, 1000.0, 1500.0, 2000.0, 2500.0] 560 cpmg_frqs_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 561 562 # Loop over the files, reading in the data. 563 for data_type, id, file, exp_type, spin_id, H_frq, relax_time in data: 564 # Skip undesired data. 565 if data_type not in data_list: 566 continue 567 568 # Alias the CPMG frequencies. 569 if data_type == 'SQ': 570 cpmg_frqs = cpmg_frqs_sq 571 elif data_type == '1H SQ': 572 cpmg_frqs = cpmg_frqs_1h_sq 573 elif data_type == 'DQ': 574 cpmg_frqs = cpmg_frqs_dq 575 elif data_type == 'ZQ': 576 cpmg_frqs = cpmg_frqs_zq 577 elif data_type == '1H MQ': 578 cpmg_frqs = cpmg_frqs_1h_mq 579 elif data_type == 'MQ': 580 cpmg_frqs = cpmg_frqs_mq 581 582 # Loop over each CPMG frequency. 583 for cpmg_frq in cpmg_frqs: 584 # The id. 585 new_id = "%s_%s" % (id, cpmg_frq) 586 587 # Set the NMR field strength. 588 self.interpreter.spectrometer.frequency(id=new_id, frq=H_frq) 589 590 # Set the relaxation dispersion experiment type. 591 self.interpreter.relax_disp.exp_type(spectrum_id=new_id, exp_type=exp_type) 592 593 # Relaxation dispersion CPMG constant time delay T (in s). 594 self.interpreter.relax_disp.relax_time(spectrum_id=new_id, time=relax_time) 595 596 # Set the CPMG frequency. 597 self.interpreter.relax_disp.cpmg_setup(spectrum_id=new_id, cpmg_frq=cpmg_frq) 598 599 # Read the R2eff data. 600 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 601 602 # Change the model. 603 self.interpreter.relax_disp.select_model('NS MMQ 2-site')
604 605
606 - def setup_sod1wt_t25(self, pipe_name, pipe_type, pipe_name_r2eff, select_spin_index):
607 """Setup of data SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 608 609 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 610 'SOD1-WT' CPMG data to the CR72 dispersion model. 611 612 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 613 Data is for experiment at 25 degree Celcius. 614 """ 615 616 # Create the data pipe and load the base data. 617 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'sod1wt_t25' 618 619 # Set experiment settings. sfrq, time_T2, ncyc 620 Exps = [ 621 ["600MHz", "Z_A", 599.8908617*1E6, 0.06, [28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 50, 18, 40, 6, 12, 0, 24], ["Z_A1", "Z_A15"] ], 622 ["500MHz", "Z_B", 499.862139*1E6, 0.04, [20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0], ["Z_B1", "Z_B18"] ] ] 623 624 # Create base pipe 625 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 626 627 # Loop throug experiments 628 id_lists = [] 629 for folder, key, sfrq, time_T2, ncycs, rep_ncyss in Exps: 630 # Read spins 631 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 632 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 633 634 # Make spectrum id list 635 id_list = list(key+str(i) for i in range(len(ncycs))) 636 id_lists.append(id_list) 637 638 # Read intensities 639 self.interpreter.spectrum.read_intensities(file="128_FT.ser", dir=data_path+sep+folder, int_method='height', spectrum_id=id_list, int_col=list(range(len(id_list))) ) 640 641 # Loop over experiments 642 for i in range(len(ncycs)): 643 ncyc = ncycs[i] 644 vcpmg = ncyc/time_T2 645 646 # Test if spectrum is a reference 647 if float(vcpmg) == 0.0: 648 vcpmg = None 649 else: 650 vcpmg = round(float(vcpmg), 3) 651 652 # Set current id 653 current_id = id_list[i] 654 655 # Set the current experiment type. 656 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 657 658 # Set the NMR field strength of the spectrum. 659 self.interpreter.spectrometer.frequency(id=current_id, frq=sfrq, units='Hz') 660 661 # Relaxation dispersion CPMG constant time delay T (in s). 662 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 663 664 # Set the relaxation dispersion CPMG frequencies. 665 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 666 667 # Define replicated 668 self.interpreter.spectrum.replicated(spectrum_ids=Exps[0][5]) 669 self.interpreter.spectrum.replicated(spectrum_ids=Exps[1][5]) 670 671 # Perform error analysis 672 self.interpreter.spectrum.error_analysis(subset=id_lists[0]) 673 self.interpreter.spectrum.error_analysis(subset=id_lists[1]) 674 675 # Define isotope 676 self.interpreter.spin.isotope(isotope='15N') 677 678 ############# 679 680 # Define the 64 residues which was used for Global fitting 681 glob_assn = ["G10N-H", "D11N-H", "Q15N-H", "G16N-H", "G37N-H", "G41N-H", "L42N-H", "H43N-H", "H46N-H", "V47N-H", "E49N-H", 682 "E50N-H", "E51N-H", "N53N-H", "T54N-H", "G56N-H", "C57N-H", "T58N-H", "G61N-H", "H63aN-H", "F64aN-H", "N65aN-H", 683 "L67N-H", "S68N-H", "K70N-H", "G72N-H", "G73N-H", "K75N-H", "E78N-H", "R79N-H", "H80N-H", "V81N-H", "G82N-H", 684 "G85N-H", "N86N-H", "V87N-H", "S102N-H", "V103N-H", "I104N-H", "S105N-H", "A111N-H", "I112N-H", "R115N-H", 685 "V118N-H", "E121N-H", "A123N-H", "L126N-H", "G127N-H", "K128N-H", "G129N-H", "G130N-H", "N131N-H", "E133N-H", 686 "S134N-H", "T135N-H", "T137N-H", "G138N-H", "N139N-H", "A140N-H", "G141N-H", "S142N-H", "R143N-H", "C146N-H", "G147N-H"] 687 688 # Test number of global 689 self.assertEqual(64, len(glob_assn )) 690 691 ## Turn assignments into relax spin ids. 692 # Define regular expression search 693 r = re.compile("([a-zA-Z]+)([0-9]+)([a-zA-Z]+)") 694 695 # Create list to hold regular expression search 696 relax_glob_ids = [] 697 698 # Loop over assignments 699 for assn in glob_assn: 700 # Make match for the regular search 701 m = r.match(assn) 702 # Convert to relax spin string 703 relax_string = ":%s@%s"%(m.group(2), m.group(3)) 704 705 # Save the relax spin string and the regular search 706 relax_glob_ids.append([m.group(0), m.group(1), m.group(2), m.group(3), relax_string]) 707 708 ############# Deselect all spins, and select few spins 709 710 ## Deselect all spins, and select a few for analysis 711 self.interpreter.deselect.all() 712 713 # Select few spins 714 for i in select_spin_index: 715 self.interpreter.select.spin(spin_id=relax_glob_ids[i][4], change_all=False) 716 717 ############## 718 719 # Prepare for R2eff calculation 720 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 721 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 722 723 # Select model for points calculation 724 MODEL = "R2eff" 725 self.interpreter.relax_disp.select_model(model=MODEL) 726 # Calculate R2eff values 727 self.interpreter.minimise.calculate(verbosity=1)
728 729
730 - def setup_missing_r1_spins(self):
731 """Function for setting up a few spins for the given pipe.""" 732 733 # Path to file. 734 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 735 736 # File with spins. 737 file = open(data_path+sep+'R1_fitted_values.txt') 738 lines = file.readlines() 739 file.close() 740 741 for i, line in enumerate(lines): 742 # Make the string test 743 line_split = line.split() 744 745 if line_split[0] == "#": 746 continue 747 748 mol_name = line_split[0] 749 mol_name = None 750 res_num = int(line_split[1]) 751 res_name = line_split[2] 752 spin_num = line_split[3] 753 spin_num = None 754 spin_name = line_split[4] 755 756 # Create the spin. 757 self.interpreter.spin.create(spin_name=spin_name, spin_num=spin_num, res_name=res_name, res_num=res_num, mol_name=mol_name)
758 759
760 - def setup_tp02_data_to_ns_r1rho_2site(self, clustering=False):
761 """Setup data for the test of relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 762 763 # Reset. 764 self.interpreter.reset() 765 766 # Create the data pipe and load the base data. 767 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 768 self.interpreter.state.load(data_path+sep+'r2eff_values') 769 770 # The model data pipe. 771 model = 'NS R1rho 2-site' 772 pipe_name = "%s - relax_disp" % model 773 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 774 self.interpreter.pipe.switch(pipe_name=pipe_name) 775 776 # Set the model. 777 self.interpreter.relax_disp.select_model(model=model) 778 779 # Copy the data. 780 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 781 782 # Alias the spins. 783 spin1 = cdp.mol[0].res[0].spin[0] 784 spin2 = cdp.mol[0].res[1].spin[0] 785 786 # The R20 keys. 787 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 788 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 789 790 # Set the initial parameter values. 791 spin1.r2 = {r20_key1: 9.9963793866185, r20_key2: 15.0056724422684} 792 spin1.pA = 0.779782428085762 793 spin1.dw = 7.57855284496424 794 spin1.kex = 1116.7911285203 795 spin2.r2 = {r20_key1: 11.9983346935434, r20_key2: 18.0076097513337} 796 spin2.pA = 0.826666229688602 797 spin2.dw = 9.5732624231366 798 spin2.kex = 1380.46162655657 799 800 # Test the values when clustering. 801 if clustering: 802 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-100") 803 804 # Low precision optimisation. 805 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 806 807 # Printout. 808 print("\n\nOptimised parameters:\n") 809 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 810 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 811 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 812 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 813 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 814 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 815 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
816 817
818 - def test_baldwin_synthetic(self):
819 """Test synthetic data of Andrew J. Baldwin B14 model whereby the simplification R20A = R20B is assumed. 820 821 Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 822 823 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>} with R20A, R20B = 2. rad/s. 824 """ 825 826 # The path to the data files. 827 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 828 829 # Create pipe 830 pipe_name = 'base pipe' 831 pipe_type = 'relax_disp' 832 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 833 834 # Create base pipe 835 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 836 837 # Generate the sequence. 838 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 839 840 # Define the isotope. 841 self.interpreter.spin.isotope('1H', spin_id='@H') 842 843 # Build the experiment IDs. 844 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 845 ncycs = [2, 4, 8, 10, 20, 40, 500] 846 ids = [] 847 for ncyc in ncycs: 848 ids.append('CPMG_%s' % ncyc) 849 850 print("\n\nThe experiment IDs are %s." % ids) 851 852 # Set up the metadata for the experiments. 853 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 854 sfrq = 200. * 1E6 855 856 # Total time of CPMG block. 857 Trelax = 0.04 858 859 # First set the 860 for i in range(len(ids)): 861 id = ids[i] 862 # Set the spectrometer frequency. 863 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 864 865 # Set the experiment type. 866 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 867 868 # Set the relaxation dispersion CPMG constant time delay T (in s). 869 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 870 871 # Set the relaxation dispersion CPMG frequencies. 872 ncyc = ncycs[i] 873 nu_cpmg = ncyc / Trelax 874 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 875 876 # Prepare for R2eff reading. 877 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 878 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 879 880 # Try reading the R2eff file. 881 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_r2a_eq_r2b_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 882 883 # Check the global data. 884 data = [ 885 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 886 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 887 ['dispersion_points', len(ncycs)], 888 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 889 ['exp_type_list', ['SQ CPMG']], 890 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 891 ['spectrometer_frq_count', 1], 892 ['spectrometer_frq_list', [sfrq]], 893 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 894 ] 895 for name, value in data: 896 # Does it exist? 897 self.assert_(hasattr(cdp, name)) 898 899 # Check the object. 900 obj = getattr(cdp, name) 901 if not isinstance(data, dict): 902 self.assertEqual(obj, value) 903 904 # Check the global dictionary data. 905 else: 906 for id in ids: 907 self.assertEqual(obj[id], value[id]) 908 909 # Check the spin data. 910 n_data = [ 911 [ 50.000000, 10.367900, 0.1], 912 [ 100.000000, 10.146849, 0.1], 913 [ 200.000000, 9.765987, 0.1], 914 [ 250.000000, 9.409789, 0.1], 915 [ 500.000000, 5.829819, 0.1], 916 [ 1000.000000, 3.191928, 0.1], 917 [ 12500.000000, 2.008231, 0.1] 918 ] 919 for disp_point, value, error in n_data: 920 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 921 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 922 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 923 924 # Generate r20 key. 925 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 926 927 ## Now prepare for MODEL calculation. 928 MODEL = "B14" 929 930 # Change pipe. 931 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 932 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 933 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 934 935 # Then select model. 936 self.interpreter.relax_disp.select_model(model=MODEL) 937 938 # Store grid and minimisations results. 939 grid_results = [] 940 mini_results = [] 941 942 # The grid search size (the number of increments per dimension). 943 # If None, use the default values. 944 #GRID = None 945 GRID = 13 946 # Perform Grid Search. 947 if GRID: 948 # Set the R20 parameters in the default grid search using the minimum R2eff value. 949 # This speeds it up considerably. 950 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 951 952 # Then do grid search. 953 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 954 955 # If no Grid search, set the default values. 956 else: 957 for param in MODEL_PARAMS[MODEL]: 958 self.interpreter.value.set(param=param, index=None) 959 # Do a grid search, which will store the chi2 value. 960 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 961 962 # Store result. 963 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 964 grid_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 965 966 ## Now do minimisation. 967 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 968 set_func_tol = 1e-10 969 set_max_iter = 1000 970 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 971 972 # Store result. 973 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 974 mini_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 975 976 # Print results. 977 for i in range(len(grid_results)): 978 g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 979 m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 980 print("GRID %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 981 print("MIN %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 982 983 # Reference values from Baldwin.py. 984 # Exchange rate = k+ + k- (s-1) 985 kex = 1000. 986 # Fractional population of excited state k+/kex 987 pb = 0.01 988 # deltaOmega in ppm 989 dw_ppm = 2. 990 #relaxation rate of ground (s-1) 991 R2g = 2. 992 #relaxation rate of excited (s-1) 993 R2e = 2. 994 995 # Test the parameters which created the data. 996 # This is for the 1H spin. 997 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2[r20_key], R2g, 6) 998 999 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1000 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 8) 1001 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex, kex, 3)
1002 1003
1005 """Test synthetic data of Andrew J. Baldwin B14 model. Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 1006 1007 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>}. 1008 """ 1009 1010 # The path to the data files. 1011 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 1012 1013 # Create pipe 1014 pipe_name = 'base pipe' 1015 pipe_type = 'relax_disp' 1016 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 1017 1018 # Create base pipe 1019 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 1020 1021 # Generate the sequence. 1022 # Generate both a 1H spin, and 15N spin. 1023 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 1024 1025 # Define the isotope. 1026 self.interpreter.spin.isotope('1H', spin_id='@H') 1027 1028 # Build the experiment IDs. 1029 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 1030 ncycs = [2, 4, 8, 10, 20, 40, 500] 1031 ids = [] 1032 for ncyc in ncycs: 1033 ids.append('CPMG_%s' % ncyc) 1034 1035 print("\n\nThe experiment IDs are %s." % ids) 1036 1037 # Set up the metadata for the experiments. 1038 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 1039 sfrq = 200. * 1E6 1040 1041 # Total time of CPMG block. 1042 Trelax = 0.04 1043 1044 # First set the 1045 for i in range(len(ids)): 1046 id = ids[i] 1047 # Set the spectrometer frequency. 1048 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 1049 1050 # Set the experiment type. 1051 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 1052 1053 # Set the relaxation dispersion CPMG constant time delay T (in s). 1054 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 1055 1056 # Set the relaxation dispersion CPMG frequencies. 1057 ncyc = ncycs[i] 1058 nu_cpmg = ncyc / Trelax 1059 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 1060 1061 # Prepare for R2eff reading. 1062 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 1063 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 1064 1065 # Try reading the R2eff file. 1066 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 1067 1068 # Check the global data. 1069 data = [ 1070 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 1071 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 1072 ['dispersion_points', len(ncycs)], 1073 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 1074 ['exp_type_list', ['SQ CPMG']], 1075 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 1076 ['spectrometer_frq_count', 1], 1077 ['spectrometer_frq_list', [sfrq]], 1078 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 1079 ] 1080 for name, value in data: 1081 # Does it exist? 1082 self.assert_(hasattr(cdp, name)) 1083 1084 # Check the object. 1085 obj = getattr(cdp, name) 1086 if not isinstance(data, dict): 1087 self.assertEqual(obj, value) 1088 1089 # Check the global dictionary data. 1090 else: 1091 for id in ids: 1092 self.assertEqual(obj[id], value[id]) 1093 1094 # Check the spin data. 1095 n_data = [ 1096 [ 50.000000, 10.286255, 0.1], 1097 [ 100.000000, 10.073083, 0.1], 1098 [ 200.000000, 9.692746, 0.1], 1099 [ 250.000000, 9.382441, 0.1], 1100 [ 500.000000, 6.312396, 0.1], 1101 [ 1000.000000, 3.957029, 0.1], 1102 [ 12500.000000, 2.880420, 0.1] 1103 ] 1104 for disp_point, value, error in n_data: 1105 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 1106 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 1107 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 1108 1109 # Generate r20 key. 1110 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 1111 1112 ## Now prepare for MODEL calculation. 1113 MODEL = "B14 full" 1114 1115 # Change pipe. 1116 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 1117 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 1118 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 1119 1120 # Then select model. 1121 self.interpreter.relax_disp.select_model(model=MODEL) 1122 1123 # Store grid and minimisations results. 1124 grid_results = [] 1125 mini_results = [] 1126 clust_results = [] 1127 1128 # The grid search size (the number of increments per dimension). 1129 # If None, use the default values. 1130 #GRID = None 1131 GRID = 13 1132 # Perform Grid Search. 1133 if GRID: 1134 # Set the R20 parameters in the default grid search using the minimum R2eff value. 1135 # This speeds it up considerably. 1136 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 1137 1138 # Then do grid search. 1139 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 1140 1141 # If no Grid search, set the default values. 1142 else: 1143 for param in MODEL_PARAMS[MODEL]: 1144 self.interpreter.value.set(param=param, index=None) 1145 # Do a grid search, which will store the chi2 value. 1146 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 1147 1148 # Store result. 1149 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1150 grid_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1151 1152 ## Now do minimisation. 1153 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 1154 set_func_tol = 1e-11 1155 set_max_iter = 10000 1156 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1157 1158 # Store result. 1159 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1160 mini_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1161 1162 print("\n# Now print before and after minimisation-\n") 1163 1164 # Print results. 1165 for i in range(len(grid_results)): 1166 g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1167 m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1168 print("GRID %s r2a=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1169 print("MIN %s r2b=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1170 1171 # Reference values from Baldwin.py. 1172 # Exchange rate = k+ + k- (s-1) 1173 kex = 1000. 1174 # Fractional population of excited state k+/kex 1175 pb = 0.01 1176 # deltaOmega in ppm 1177 dw_ppm = 2. 1178 #relaxation rate of ground (s-1) 1179 R2g = 2. 1180 #relaxation rate of excited (s-1) 1181 R2e = 100. 1182 1183 # Test the parameters which created the data. 1184 # This is for the 1H spin. 1185 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2a[r20_key], R2g, 4) 1186 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2b[r20_key], R2e, 2) 1187 1188 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1189 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 6) 1190 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex, kex, 2)
1191 1192
1194 """U{Bug #21081<https://gna.org/bugs/?21081>} catch, the failure of a cluster analysis when spins are deselected.""" 1195 1196 # Clear the data store. 1197 self.interpreter.reset() 1198 1199 # Load the state. 1200 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21081_disp_cluster_fail.bz2' 1201 self.interpreter.state.load(state, force=True) 1202 1203 # Model selection - to catch the failure. 1204 self.interpreter.model_selection(method='AIC', modsel_pipe='final', bundle='relax_disp', pipes=['No Rex', 'CR72'])
1205 1206
1208 """U{Bug #21460<https://gna.org/bugs/?21460>} catch, the failure due to a spectrometer frequency having no relaxation data.""" 1209 1210 # Clear the data store. 1211 self.interpreter.reset() 1212 1213 # Load the state. 1214 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21460_bad_fields.bz2' 1215 self.interpreter.state.load(state, force=True) 1216 1217 # Execute the auto-analysis (fast). 1218 relax_disp.Relax_disp.opt_func_tol = 1e-5 1219 relax_disp.Relax_disp.opt_max_iterations = 1000 1220 relax_disp.Relax_disp(pipe_name="origin - relax_disp (Thu Jan 2 13:46:44 2014)", pipe_bundle="relax_disp (Thu Jan 2 13:46:44 2014)", results_dir=self.tmpdir, models=['R2eff', 'No Rex', 'CR72', 'NS CPMG 2-site expanded'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1221 1222
1224 """U{Bug #21665<https://gna.org/bugs/?21344>} catch, the failure of an analysis of a sparse acquired R1rho dataset with missing combinations of time and spin-lock field strengths using auto_analysis.""" 1225 1226 # Clear the data store. 1227 self.interpreter.reset() 1228 1229 # Load the state. 1230 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 1231 self.interpreter.state.load(state, force=True) 1232 1233 # Execute the auto-analysis (fast). 1234 relax_disp.Relax_disp.opt_func_tol = 1e-5 1235 relax_disp.Relax_disp.opt_max_iterations = 1000 1236 relax_disp.Relax_disp(pipe_name='base pipe', pipe_bundle='relax_disp', results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1237 1238
1240 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times, using minimise.calculate().""" 1241 1242 # Clear the data store. 1243 self.interpreter.reset() 1244 1245 # Load the state. 1246 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1247 self.interpreter.state.load(state, force=True) 1248 1249 # Run the calculation. 1250 self.interpreter.minimise.calculate(verbosity=1)
1251 1252
1254 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times using auto_analysis.""" 1255 1256 # Clear the data store. 1257 self.interpreter.reset() 1258 1259 # Load the state. 1260 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1261 self.interpreter.state.load(state, force=True) 1262 1263 # Execute the auto-analysis (fast). 1264 relax_disp.Relax_disp.opt_func_tol = 1e-5 1265 relax_disp.Relax_disp.opt_max_iterations = 1000 1266 relax_disp.Relax_disp(pipe_name="compare_128_FT_R2eff", pipe_bundle="cpmg_disp_sod1d90a", results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1267 1268
1270 """Catch U{bug #21715<https://gna.org/bugs/?21715>}, the failure of a clustered auto-analysis due to an IndexError.""" 1271 1272 # Clear the data store. 1273 self.interpreter.reset() 1274 1275 # Load the state. 1276 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'state.bz2' 1277 self.interpreter.state.load(state, force=True) 1278 1279 # Execute the auto-analysis (fast). 1280 pre_run_dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'non_clustered' 1281 relax_disp.Relax_disp.opt_func_tol = 1e-5 1282 relax_disp.Relax_disp.opt_max_iterations = 1000 1283 relax_disp.Relax_disp(pipe_name='origin - relax_disp (Sun Feb 23 19:36:51 2014)', pipe_bundle='relax_disp (Sun Feb 23 19:36:51 2014)', results_dir=self.tmpdir, models=['R2eff', 'No Rex'], grid_inc=11, mc_sim_num=2, modsel='AIC', pre_run_dir=pre_run_dir, insignificance=1.0, numeric_only=True, mc_sim_all_models=False, eliminate=True)
1284 1285
1287 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered B14 full analysis.""" 1288 1289 # Base data setup. 1290 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='B14_full', model_analyse = MODEL_B14_FULL)
1291 1292
1294 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered CR72 full analysis.""" 1295 1296 # Base data setup. 1297 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='CR72_full', model_analyse = MODEL_CR72_FULL)
1298 1299
1301 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE 3D full analysis.""" 1302 1303 # Base data setup. 1304 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_3d_full', model_analyse = MODEL_NS_CPMG_2SITE_3D_FULL)
1305 1306
1308 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE STAR full analysis.""" 1309 1310 # Base data setup. 1311 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_star_full', model_analyse = MODEL_NS_CPMG_2SITE_STAR_FULL, places = 4)
1312 1313
1315 """Catch U{bug #22146<https://gna.org/bugs/?22477>}, the failure of issuing: grace.write(x_data_type='res_num', y_data_type=param) for a mixed CPMG analysis.""" 1316 1317 # Clear the data store. 1318 self.interpreter.reset() 1319 1320 # Load the state. 1321 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22477_grace_write_k_AB_mixed_analysis'+sep+'bug_22477_results.bz2' 1322 self.interpreter.state.load(state, force=True) 1323 1324 param = 'k_AB' 1325 1326 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1327 print(spin_id, spin.params) 1328 if param in spin.params: 1329 print(spin_id, spin.k_AB, spin.k_AB_err) 1330 1331 # Perform write. 1332 self.interpreter.grace.write(x_data_type='res_num', y_data_type=param, file='%s.agr'%param, dir=self.tmpdir, force=True) 1333 1334 1335 # Test the header of the value.write parameter r2. 1336 param = 'r2' 1337 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1338 1339 file = open(self.tmpdir+sep+'%s.out'%param) 1340 lines = file.readlines() 1341 file.close() 1342 1343 for i, line in enumerate(lines): 1344 # Make the string test 1345 line_split = line.split() 1346 print(line_split) 1347 1348 if len(line_split) > 1: 1349 # Break at parameter header. 1350 if line_split[0] == "#" and line_split[1] == 'mol_name': 1351 nr_split_header = len(line_split) 1352 nr_split_header_i = i 1353 break 1354 1355 # Call the line after. 1356 line_split_val = lines[nr_split_header_i + 1].split() 1357 print(line_split_val) 1358 1359 # Assert that the number of columns is equal, plus 1 for "#". 1360 self.assertEqual(nr_split_header, len(line_split_val) + 1) 1361 1362 # Test the header of the value.write for parameter r2eff. 1363 param = 'r2eff' 1364 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1365 1366 file = open(self.tmpdir+sep+'%s.out'%param) 1367 lines = file.readlines() 1368 file.close() 1369 1370 for i, line in enumerate(lines): 1371 # Make the string test 1372 line_split = line.split() 1373 print(line_split) 1374 1375 if len(line_split) > 1: 1376 # Break at parameter header. 1377 if line_split[0] == "#" and line_split[1] == 'mol_name': 1378 nr_split_header = len(line_split) 1379 nr_split_header_i = i 1380 break 1381 1382 # Call the line after. 1383 line_split_val = lines[nr_split_header_i + 1].split() 1384 print(line_split_val) 1385 1386 # Assert that the number of columns is equal, plus 1 for "#". 1387 self.assertEqual(nr_split_header, len(line_split_val) + 1)
1388 1389
1391 """Catch U{bug #9999<https://gna.org/bugs/?9999>}, The slow optimisation of R1rho R2eff error estimation with Monte Carlo simulations.""" 1392 1393 # Define path to data 1394 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 1395 1396 # Read data. 1397 self.interpreter.results.read(prev_data_path + sep + 'results') 1398 1399 # Now count number 1400 graph_nr = 1 1401 for exp_type, frq, offset, point in loop_exp_frq_offset_point(return_indices=False): 1402 print("\nGraph nr %i" % graph_nr) 1403 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 1404 print(exp_type, frq, offset, point, time) 1405 graph_nr += 1 1406 1407 ## Possibly do an error analysis. 1408 1409 # Check if intensity errors have already been calculated by the user. 1410 precalc = True 1411 for spin in spin_loop(skip_desel=True): 1412 # No structure. 1413 if not hasattr(spin, 'peak_intensity_err'): 1414 precalc = False 1415 break 1416 1417 # Determine if a spectrum ID is missing from the list. 1418 for id in cdp.spectrum_ids: 1419 if id not in spin.peak_intensity_err: 1420 precalc = False 1421 break 1422 1423 # Skip. 1424 if precalc: 1425 print("Skipping the error analysis as it has already been performed.") 1426 1427 else: 1428 # Loop over the spectrometer frequencies. 1429 for frq in loop_frq(): 1430 # Generate a list of spectrum IDs matching the frequency. 1431 ids = [] 1432 for id in cdp.spectrum_ids: 1433 # Check that the spectrometer frequency matches. 1434 match_frq = True 1435 if frq != None and cdp.spectrometer_frq[id] != frq: 1436 match_frq = False 1437 1438 # Add the ID. 1439 if match_frq: 1440 ids.append(id) 1441 1442 # Run the error analysis on the subset. 1443 self.interpreter.spectrum.error_analysis(subset=ids) 1444 1445 print("has_exponential_exp_type:", has_exponential_exp_type()) 1446 1447 model = 'R2eff' 1448 self.interpreter.relax_disp.select_model(model) 1449 1450 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1451 #delattr(spin, 'r2eff') 1452 #delattr(spin, 'r2eff_err') 1453 #delattr(spin, 'i0') 1454 #delattr(spin, 'i0_err') 1455 setattr(spin, 'r2eff', {}) 1456 setattr(spin, 'r2eff_err', {}) 1457 setattr(spin, 'i0', {}) 1458 setattr(spin, 'i0_err', {}) 1459 1460 # Do Grid Search 1461 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=21, constraints=True, verbosity=1) 1462 1463 # Start dic. 1464 my_dic = {} 1465 1466 # Define counter for maximum elements in the numpy array list 1467 NE = 0 1468 NS = 1 1469 NM = 0 1470 NO = 0 1471 ND = 0 1472 NT = 0 1473 1474 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1475 # Save to counter. 1476 if ei > NE: 1477 NE = ei 1478 if mi > NM: 1479 NM = mi 1480 if oi > NO: 1481 NO = oi 1482 if di > ND: 1483 ND = di 1484 1485 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1486 # Save to counter. 1487 if ti > NT: 1488 NT = ti 1489 1490 # Add 1 to counter, since index start from 0. 1491 NE = NE + 1 1492 NM = NM + 1 1493 NO = NO + 1 1494 ND = ND + 1 1495 NT = NT + 1 1496 1497 # Make data array. 1498 values_arr = zeros([NE, NS, NM, NO, ND, NT]) 1499 errors_arr = zeros([NE, NS, NM, NO, ND, NT]) 1500 times_arr = zeros([NE, NS, NM, NO, ND, NT]) 1501 struct_arr = zeros([NE, NS, NM, NO, ND, NT]) 1502 param_key_list = [] 1503 1504 1505 # Loop over each spectrometer frequency and dispersion point. 1506 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1507 # Add key to dic. 1508 my_dic[spin_id] = {} 1509 1510 # Generate spin string. 1511 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1512 1513 # Loop over the parameters. 1514 #print("Grid optimised parameters for spin: %s" % (spin_string)) 1515 1516 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1517 # Generate the param_key. 1518 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1519 1520 # Append key. 1521 param_key_list.append(param_key) 1522 1523 # Add key to dic. 1524 my_dic[spin_id][param_key] = {} 1525 1526 # Get the value. 1527 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1528 i0_value = getattr(cur_spin, 'i0')[param_key] 1529 1530 # Save to dic. 1531 my_dic[spin_id][param_key]['R2eff_value_grid'] = R2eff_value 1532 my_dic[spin_id][param_key]['i0_value_grid'] = i0_value 1533 1534 ## Now try do a line of best fit by least squares. 1535 # The peak intensities, errors and times. 1536 values = [] 1537 errors = [] 1538 times = [] 1539 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1540 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1541 values.append(value) 1542 1543 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1544 errors.append(error) 1545 times.append(time) 1546 1547 # Save to numpy arrays. 1548 values_arr[ei, 0, mi, oi, di, ti] = value 1549 errors_arr[ei, 0, mi, oi, di, ti] = error 1550 times_arr[ei, 0, mi, oi, di, ti] = time 1551 struct_arr[ei, 0, mi, oi, di, ti] = 1.0 1552 1553 # y= A exp(x * k) 1554 # w[i] = ln(y[i]) 1555 # int[i] = i0 * exp( - times[i] * r2eff); 1556 w = log(array(values)) 1557 x = - array(times) 1558 n = len(times) 1559 1560 b = (sum(x*w) - 1./n * sum(x) * sum(w) ) / ( sum(x**2) - 1./n * (sum(x))**2 ) 1561 a = 1./n * sum(w) - b * 1./n * sum(x) 1562 R2eff_est = b 1563 i0_est = exp(a) 1564 1565 my_dic[spin_id][param_key]['R2eff_est'] = R2eff_est 1566 my_dic[spin_id][param_key]['i0_est'] = i0_est 1567 1568 # Print value. 1569 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1570 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1571 1572 1573 # Do minimisation. 1574 set_func_tol = 1e-25 1575 set_max_iter = int(1e7) 1576 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1577 1578 # Loop over each spectrometer frequency and dispersion point. 1579 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1580 # Generate spin string. 1581 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1582 1583 # Loop over the parameters. 1584 print("Optimised parameters for spin: %s" % (spin_string)) 1585 1586 for exp_type, frq, offset, point in loop_exp_frq_offset_point(): 1587 # Generate the param_key. 1588 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1589 1590 # Get the value. 1591 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1592 i0_value = getattr(cur_spin, 'i0')[param_key] 1593 1594 # Extract from dic. 1595 R2eff_value_grid = my_dic[spin_id][param_key]['R2eff_value_grid'] 1596 i0_value_grid = my_dic[spin_id][param_key]['i0_value_grid'] 1597 R2eff_est = my_dic[spin_id][param_key]['R2eff_est'] 1598 i0_est = my_dic[spin_id][param_key]['i0_est'] 1599 1600 # Print value. 1601 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1602 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1603 1604 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'R2eff', "Grid : Min : Estimated:", R2eff_value_grid, R2eff_value, R2eff_est)) 1605 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'i0', "Grid : Min : Estimated:", i0_value_grid, i0_value, i0_est)) 1606 1607 print(NE, NS, NM, NO, ND, NT) 1608 for param_key in param_key_list: 1609 print(" '%s'," % param_key) 1610 print(values_arr.shape) 1611 1612 # Save arrays to profiling. 1613 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'curve_fitting'+sep+'profiling'+sep
1614 #save(data_path + "values_arr", values_arr) 1615 #save(data_path + "errors_arr", errors_arr) 1616 #save(data_path + "times_arr", times_arr) 1617 #save(data_path + "struct_arr", struct_arr) 1618 1619
1620 - def test_bug_atul_srivastava(self):
1621 """Test data from Atul Srivastava. This is a bug missing raising a Relax Error, since the setup points to a situation where the data 1622 shows it is exponential fitting, but only one time point is added per file. 1623 1624 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1718>}: 1625 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735>}: 1626 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735/focus=1736>}: 1627 1628 """ 1629 1630 # Data path. 1631 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_Atul_Srivastava' 1632 file = data_path + sep + 'bug_script.py' 1633 1634 # Run script. 1635 self.interpreter.script(file=file, dir=None) 1636 1637 # The grid search size (the number of increments per dimension). 1638 GRID_INC = 11 1639 1640 # Check-data. 1641 ################# 1642 1643 # Loop over spins, to see current setup. 1644 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1645 print(mol_name, resi, resn, spin_id) 1646 1647 # Loop over setup. 1648 for id in cdp.exp_type.keys(): 1649 print(id, cdp.exp_type[id], cdp.spectrometer_frq[id], cdp.spin_lock_offset[id], cdp.spin_lock_nu1[id]) 1650 1651 1652 # Manual minimisation. 1653 ################# 1654 if True: 1655 # Set the model. 1656 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 1657 1658 # Check if intensity errors have already been calculated. 1659 check_intensity_errors() 1660 1661 # Calculate the R2eff values for the fixed relaxation time period data types. 1662 if cdp.model_type == MODEL_R2EFF and not has_exponential_exp_type(): 1663 self.interpreter.minimise.calculate() 1664 1665 # Optimise the model. 1666 else: 1667 constraints = False 1668 min_algor = 'Newton' 1669 with self.assertRaises(RelaxError): 1670 self.interpreter.minimise.grid_search(inc=GRID_INC) 1671 1672 with self.assertRaises(RelaxError): 1673 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints) 1674 # Inspect. 1675 if False: 1676 # Loop over attributes. 1677 par_attr_list = ['r2eff', 'i0'] 1678 1679 # Collect the estimation data. 1680 my_dic = {} 1681 param_key_list = [] 1682 est_keys = [] 1683 est_key = 'grid' 1684 est_keys.append(est_key) 1685 spin_id_list = [] 1686 1687 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1688 # Add key to dic. 1689 my_dic[spin_id] = {} 1690 1691 # Add key for estimate. 1692 my_dic[spin_id][est_key] = {} 1693 1694 # Add spin key to list. 1695 spin_id_list.append(spin_id) 1696 1697 # Generate spin string. 1698 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1699 1700 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1701 # Generate the param_key. 1702 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1703 #param_key = generate_r20_key(exp_type=exp_type, frq=frq) 1704 1705 # Append key. 1706 param_key_list.append(param_key) 1707 1708 # Add key to dic. 1709 my_dic[spin_id][est_key][param_key] = {} 1710 1711 # Get the value. 1712 # Loop over err attributes. 1713 for par_attr in par_attr_list: 1714 if hasattr(cur_spin, par_attr): 1715 get_par_attr = getattr(cur_spin, par_attr)[param_key] 1716 else: 1717 get_par_attr = 0.0 1718 1719 # Save to dic. 1720 my_dic[spin_id][est_key][param_key][par_attr] = get_par_attr 1721 1722 # Check number of values. 1723 values = [] 1724 errors = [] 1725 times = [] 1726 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1727 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1728 values.append(value) 1729 1730 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1731 errors.append(error) 1732 times.append(time) 1733 1734 # Save to dic. 1735 my_dic[spin_id][est_key][param_key]['values'] = values 1736 my_dic[spin_id][est_key][param_key]['errors'] = errors 1737 my_dic[spin_id][est_key][param_key]['times'] = times 1738 1739 # Analysis variables. 1740 ##################### 1741 1742 # The dispersion models. 1743 MODELS = ['R2eff', 'No Rex'] 1744 1745 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 1746 MC_NUM = 10 1747 1748 # A flag which if True will activate Monte Carlo simulations for all models. Note this will hugely increase the computation time. 1749 MC_SIM_ALL_MODELS = False 1750 1751 # The results directory. 1752 RESULTS_DIR = ds.tmpdir 1753 1754 # The directory of results of an earlier analysis without clustering. 1755 PRE_RUN_DIR = None 1756 1757 # The model selection technique to use. 1758 MODSEL = 'AIC' 1759 1760 # The flag for only using numeric models in the final model selection. 1761 NUMERIC_ONLY = False 1762 1763 # The R1rho value in rad/s by which to judge insignificance. If the maximum difference between two points on all dispersion curves for a spin is less than this value, that spin will be deselected. 1764 INSIGNIFICANCE = 1.0 1765 1766 # Auto-analysis execution. 1767 with self.assertRaises(RelaxError): 1768 relax_disp.Relax_disp(pipe_name='relax_disp', results_dir=RESULTS_DIR, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, insignificance=INSIGNIFICANCE, numeric_only=NUMERIC_ONLY)
1769 1770
1772 """Test data, where peak intensities are negative in CPMG 1773 1774 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 1775 """ 1776 1777 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'bug_neg_int_acbp_cpmg_disp_048MGuHCl_40C_041223' 1778 1779 # Create the spins 1780 self.interpreter.spectrum.read_spins(file="peaks_list_max_standard.ser", dir=data_path) 1781 1782 # Name the isotope for field strength scaling. 1783 self.interpreter.spin.isotope(isotope='15N') 1784 1785 # Read the spectrum from NMRSeriesTab file. The "auto" will generate spectrum name of form: Z_A{i} 1786 self.interpreter.spectrum.read_intensities(file="peaks_list_max_standard.ser", dir=data_path, spectrum_id='auto', int_method='height') 1787 1788 # Loop over the spectra settings. 1789 ncycfile=open(data_path + sep + 'ncyc.txt', 'r') 1790 1791 # Make empty ncyclist 1792 ncyclist = [] 1793 1794 i = 0 1795 for line in ncycfile: 1796 ncyc = line.split()[0] 1797 time_T2 = float(line.split()[1]) 1798 vcpmg = line.split()[2] 1799 set_sfrq = float(line.split()[3]) 1800 rmsd_err = float(line.split()[4]) 1801 1802 # Test if spectrum is a reference 1803 if float(vcpmg) == 0.0: 1804 vcpmg = None 1805 else: 1806 vcpmg = round(float(vcpmg), 3) 1807 1808 # Add ncyc to list 1809 ncyclist.append(int(ncyc)) 1810 1811 # Set the current spectrum id 1812 current_id = "Z_A%s"%(i) 1813 1814 # Set the current experiment type. 1815 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 1816 1817 # Set the peak intensity errors, as defined as the baseplane RMSD. 1818 self.interpreter.spectrum.baseplane_rmsd(error=rmsd_err, spectrum_id=current_id) 1819 1820 # Set the NMR field strength of the spectrum. 1821 self.interpreter.spectrometer.frequency(id=current_id, frq=set_sfrq, units='MHz') 1822 1823 # Relaxation dispersion CPMG constant time delay T (in s). 1824 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 1825 1826 # Set the relaxation dispersion CPMG frequencies. 1827 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 1828 1829 i += 1 1830 1831 # Specify the duplicated spectra. 1832 self.interpreter.spectrum.replicated(spectrum_ids=['Z_A1', 'Z_A15']) 1833 1834 # Delete replicate spectrum 1835 #self.interpreter.spectrum.delete('Z_A15') 1836 1837 MODELS = [MODEL_R2EFF, MODEL_NOREX] 1838 GRID_INC = 5; MC_NUM = 3; MODSEL = 'AIC' 1839 1840 results_dir = ds.tmpdir 1841 1842 # Execute 1843 relax_disp.Relax_disp(pipe_name='relax_disp', results_dir=results_dir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 1844 1845 # Check spin less R2eff points. 1846 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 1847 # Assert that spin 4, has one less R2eff point, since one of the intensities are negative. 1848 if spin_id == ':4@N': 1849 self.assertEqual(len(cur_spin.r2eff), 14) 1850 else: 1851 self.assertEqual(len(cur_spin.r2eff), 15)
1852 1853
1854 - def test_check_missing_r1(self):
1855 """Test of the check_missing_r1() function.""" 1856 1857 # Set up some spins. 1858 self.setup_missing_r1_spins() 1859 1860 # Set variables. 1861 exp_type = 'R1rho' 1862 frq = 800.1 * 1E6 1863 1864 spectrum_id='test' 1865 1866 # Set an experiment type to the pipe. 1867 self.interpreter.relax_disp.exp_type(spectrum_id=spectrum_id, exp_type=exp_type) 1868 1869 # Set a frequency to loop through. 1870 self.interpreter.spectrometer.frequency(id=spectrum_id, frq=frq, units='Hz') 1871 1872 # Check R1 for DPL94. 1873 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 1874 self.assertEqual(check_missing_r1_return, True) 1875 1876 # Check R1 for R2eff. 1877 check_missing_r1_return = check_missing_r1(model=MODEL_R2EFF) 1878 self.assertEqual(check_missing_r1_return, False) 1879 1880 # The path to the data files. 1881 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 1882 1883 # Now load some R1 data. 1884 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 1885 1886 # Check R1. 1887 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 1888 self.assertEqual(check_missing_r1_return, False)
1889 1890
1892 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site 3D, for clustered analysis. 1893 1894 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 1895 1896 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 1897 """ 1898 1899 # Reset. 1900 #self.interpreter.reset() 1901 1902 ## Set Experiments. 1903 model_create = 'B14' 1904 #model_create = 'NS CPMG 2-site expanded' 1905 model_analyse = 'NS CPMG 2-site 3D' 1906 1907 # Exp 1 1908 sfrq_1 = 599.8908617*1E6 1909 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 1910 time_T2_1 = 0.06 1911 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 1912 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 1913 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 1914 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 1915 1916 sfrq_2 = 499.8908617*1E6 1917 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 1918 time_T2_2 = 0.05 1919 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 1920 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 1921 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 1922 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 1923 1924 # Collect all exps 1925 exps = [exp_1, exp_2] 1926 1927 spins = [ 1928 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 1929 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 1930 ] 1931 1932 # Collect the data to be used. 1933 ds.data = [model_create, model_analyse, spins, exps] 1934 1935 # The tmp directory. None is the local directory. 1936 ds.tmpdir = ds.tmpdir 1937 1938 # The results directory. None is the local directory. 1939 #ds.resdir = None 1940 ds.resdir = ds.tmpdir 1941 1942 # Do r20_from_min_r2eff ?. 1943 ds.r20_from_min_r2eff = True 1944 1945 # Remove insignificant level. 1946 ds.insignificance = 0.0 1947 1948 # The grid search size (the number of increments per dimension). 1949 ds.GRID_INC = None 1950 1951 # The do clustering. 1952 ds.do_cluster = True 1953 1954 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 1955 # The default value is 1e-25. 1956 ds.set_func_tol = 1e-1 1957 1958 # The maximum number of iterations. 1959 # The default value is 1e7. 1960 ds.set_max_iter = 1000 1961 1962 # The verbosity level. 1963 ds.verbosity = 1 1964 1965 # The rel_change WARNING level. 1966 ds.rel_change = 0.05 1967 1968 # The plot_curves. 1969 ds.plot_curves = False 1970 1971 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 1972 ds.sherekhan_input = False 1973 1974 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 1975 ds.opendx = False 1976 1977 # The set r2eff err. 1978 ds.r2eff_err = 0.1 1979 1980 # The print result info. 1981 ds.print_res = True 1982 1983 # Execute the script. 1984 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 1985 1986 cur_spins = ds.data[2] 1987 # Compare results. 1988 for i in range(len(cur_spins)): 1989 res_name, res_num, spin_name, params = cur_spins[i] 1990 cur_spin_id = ":%i@%s"%(res_num, spin_name) 1991 cur_spin = return_spin(cur_spin_id) 1992 1993 grid_params = ds.grid_results[i][3] 1994 1995 # Extract the clust results. 1996 min_params = ds.clust_results[i][3] 1997 # Now read the parameters. 1998 print("For spin: '%s'"%cur_spin_id) 1999 for mo_param in cur_spin.params: 2000 # The R2 is a dictionary, depending on spectrometer frequency. 2001 if isinstance(getattr(cur_spin, mo_param), dict): 2002 grid_r2 = grid_params[mo_param] 2003 min_r2 = min_params[mo_param] 2004 set_r2 = params[mo_param] 2005 for key, val in set_r2.items(): 2006 grid_r2_frq = grid_r2[key] 2007 min_r2_frq = min_r2[key] 2008 set_r2_frq = set_r2[key] 2009 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2010 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2011 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2012 if rel_change > ds.rel_change: 2013 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2014 print("###################################") 2015 2016 ## Make test on R2. 2017 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2018 else: 2019 grid_val = grid_params[mo_param] 2020 min_val = min_params[mo_param] 2021 set_val = params[mo_param] 2022 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2023 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2024 if rel_change > ds.rel_change: 2025 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2026 print("###################################") 2027 2028 ## Make test on parameters. 2029 if mo_param == 'dw': 2030 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2031 elif mo_param == 'kex': 2032 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2033 elif mo_param == 'pA': 2034 self.assertAlmostEqual(set_val, min_val, 2)
2035 2036
2038 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site STAR, for clustered analysis. 2039 2040 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 2041 2042 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2043 """ 2044 2045 # Reset. 2046 #self.interpreter.reset() 2047 2048 ## Set Experiments. 2049 model_create = 'B14' 2050 #model_create = 'NS CPMG 2-site expanded' 2051 model_analyse = 'NS CPMG 2-site star' 2052 2053 # Exp 1 2054 sfrq_1 = 599.8908617*1E6 2055 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2056 time_T2_1 = 0.06 2057 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2058 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2059 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2060 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2061 2062 sfrq_2 = 499.8908617*1E6 2063 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2064 time_T2_2 = 0.05 2065 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2066 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2067 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2068 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2069 2070 # Collect all exps 2071 exps = [exp_1, exp_2] 2072 2073 spins = [ 2074 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 2075 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 2076 ] 2077 2078 # Collect the data to be used. 2079 ds.data = [model_create, model_analyse, spins, exps] 2080 2081 # The tmp directory. None is the local directory. 2082 ds.tmpdir = ds.tmpdir 2083 2084 # The results directory. None is the local directory. 2085 #ds.resdir = None 2086 ds.resdir = ds.tmpdir 2087 2088 # Do r20_from_min_r2eff ?. 2089 ds.r20_from_min_r2eff = True 2090 2091 # Remove insignificant level. 2092 ds.insignificance = 0.0 2093 2094 # The grid search size (the number of increments per dimension). 2095 ds.GRID_INC = None 2096 2097 # The do clustering. 2098 ds.do_cluster = True 2099 2100 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2101 # The default value is 1e-25. 2102 ds.set_func_tol = 1e-1 2103 2104 # The maximum number of iterations. 2105 # The default value is 1e7. 2106 ds.set_max_iter = 1000 2107 2108 # The verbosity level. 2109 ds.verbosity = 1 2110 2111 # The rel_change WARNING level. 2112 ds.rel_change = 0.05 2113 2114 # The plot_curves. 2115 ds.plot_curves = False 2116 2117 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2118 ds.sherekhan_input = False 2119 2120 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2121 ds.opendx = False 2122 2123 # The set r2eff err. 2124 ds.r2eff_err = 0.1 2125 2126 # The print result info. 2127 ds.print_res = True 2128 2129 # Execute the script. 2130 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2131 2132 cur_spins = ds.data[2] 2133 # Compare results. 2134 for i in range(len(cur_spins)): 2135 res_name, res_num, spin_name, params = cur_spins[i] 2136 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2137 cur_spin = return_spin(cur_spin_id) 2138 2139 grid_params = ds.grid_results[i][3] 2140 2141 # Extract the clust results. 2142 min_params = ds.clust_results[i][3] 2143 # Now read the parameters. 2144 print("For spin: '%s'"%cur_spin_id) 2145 for mo_param in cur_spin.params: 2146 # The R2 is a dictionary, depending on spectrometer frequency. 2147 if isinstance(getattr(cur_spin, mo_param), dict): 2148 grid_r2 = grid_params[mo_param] 2149 min_r2 = min_params[mo_param] 2150 set_r2 = params[mo_param] 2151 for key, val in set_r2.items(): 2152 grid_r2_frq = grid_r2[key] 2153 min_r2_frq = min_r2[key] 2154 set_r2_frq = set_r2[key] 2155 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2156 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2157 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2158 if rel_change > ds.rel_change: 2159 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2160 print("###################################") 2161 2162 ## Make test on R2. 2163 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2164 else: 2165 grid_val = grid_params[mo_param] 2166 min_val = min_params[mo_param] 2167 set_val = params[mo_param] 2168 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2169 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2170 if rel_change > ds.rel_change: 2171 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2172 print("###################################") 2173 2174 ## Make test on parameters. 2175 if mo_param == 'dw': 2176 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2177 elif mo_param == 'kex': 2178 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2179 elif mo_param == 'pA': 2180 self.assertAlmostEqual(set_val, min_val, 2)
2181 2182
2184 """Test synthetic cpmg data. 2185 2186 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with CR72. 2187 """ 2188 2189 # Reset. 2190 #self.interpreter.reset() 2191 2192 ## Set Experiments. 2193 model_create = 'NS CPMG 2-site 3D' 2194 #model_create = 'NS CPMG 2-site expanded' 2195 model_analyse = 'CR72' 2196 # Exp 1 2197 sfrq_1 = 599.8908617*1E6 2198 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2199 time_T2_1 = 0.06 2200 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2201 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2202 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2203 2204 sfrq_2 = 499.8908617*1E6 2205 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2206 time_T2_2 = 0.05 2207 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2208 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2209 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2210 2211 # Collect all exps 2212 exps = [exp_1, exp_2] 2213 2214 spins = [ 2215 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2216 ] 2217 2218 # Collect the data to be used. 2219 ds.data = [model_create, model_analyse, spins, exps] 2220 2221 # The tmp directory. None is the local directory. 2222 ds.tmpdir = ds.tmpdir 2223 2224 # The results directory. None is the local directory. 2225 #ds.resdir = None 2226 ds.resdir = ds.tmpdir 2227 2228 # Do r20_from_min_r2eff ?. 2229 ds.r20_from_min_r2eff = True 2230 2231 # Remove insignificant level. 2232 ds.insignificance = 0.0 2233 2234 # The grid search size (the number of increments per dimension). 2235 ds.GRID_INC = 8 2236 2237 # The do clustering. 2238 ds.do_cluster = False 2239 2240 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2241 # The default value is 1e-25. 2242 ds.set_func_tol = 1e-9 2243 2244 # The maximum number of iterations. 2245 # The default value is 1e7. 2246 ds.set_max_iter = 1000 2247 2248 # The verbosity level. 2249 ds.verbosity = 1 2250 2251 # The rel_change WARNING level. 2252 ds.rel_change = 0.05 2253 2254 # The plot_curves. 2255 ds.plot_curves = False 2256 2257 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2258 ds.sherekhan_input = False 2259 2260 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2261 ds.opendx = False 2262 2263 # The set r2eff err. 2264 ds.r2eff_err = 0.1 2265 2266 # The print result info. 2267 ds.print_res = False 2268 2269 # Execute the script. 2270 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2271 2272 cur_spins = ds.data[2] 2273 # Compare results. 2274 for i in range(len(cur_spins)): 2275 res_name, res_num, spin_name, params = cur_spins[i] 2276 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2277 cur_spin = return_spin(cur_spin_id) 2278 2279 grid_params = ds.grid_results[i][3] 2280 min_params = ds.min_results[i][3] 2281 # Now read the parameters. 2282 print("For spin: '%s'"%cur_spin_id) 2283 for mo_param in cur_spin.params: 2284 # The R2 is a dictionary, depending on spectrometer frequency. 2285 if isinstance(getattr(cur_spin, mo_param), dict): 2286 grid_r2 = grid_params[mo_param] 2287 min_r2 = min_params[mo_param] 2288 set_r2 = params[mo_param] 2289 for key, val in set_r2.items(): 2290 grid_r2_frq = grid_r2[key] 2291 min_r2_frq = min_r2[key] 2292 set_r2_frq = set_r2[key] 2293 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2294 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2295 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2296 if rel_change > ds.rel_change: 2297 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2298 print("###################################") 2299 2300 ## Make test on R2. 2301 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2302 else: 2303 grid_val = grid_params[mo_param] 2304 min_val = min_params[mo_param] 2305 set_val = params[mo_param] 2306 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2307 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2308 if rel_change > ds.rel_change: 2309 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2310 print("###################################") 2311 2312 ## Make test on parameters. 2313 if mo_param == 'dw': 2314 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2315 elif mo_param == 'kex': 2316 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2317 elif mo_param == 'pA': 2318 self.assertAlmostEqual(set_val, min_val, 3)
2319 2320
2322 """Test synthetic cpmg data. 2323 2324 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with B14. 2325 Try to catch bug #22021 U{https://gna.org/bugs/index.php?22021}: Model B14 shows bad fitting to data. 2326 """ 2327 2328 # Reset. 2329 #self.interpreter.reset() 2330 2331 ## Set Experiments. 2332 model_create = 'NS CPMG 2-site 3D' 2333 #model_create = 'NS CPMG 2-site expanded' 2334 model_analyse = 'B14' 2335 # Exp 1 2336 sfrq_1 = 599.8908617*1E6 2337 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2338 time_T2_1 = 0.06 2339 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2340 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2341 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2342 2343 sfrq_2 = 499.8908617*1E6 2344 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2345 time_T2_2 = 0.05 2346 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2347 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2348 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2349 2350 # Collect all exps 2351 exps = [exp_1, exp_2] 2352 2353 spins = [ 2354 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2355 ] 2356 2357 # Collect the data to be used. 2358 ds.data = [model_create, model_analyse, spins, exps] 2359 2360 # The tmp directory. None is the local directory. 2361 ds.tmpdir = ds.tmpdir 2362 2363 # The results directory. None is the local directory. 2364 #ds.resdir = None 2365 ds.resdir = ds.tmpdir 2366 2367 # Do r20_from_min_r2eff ?. 2368 ds.r20_from_min_r2eff = True 2369 2370 # Remove insignificant level. 2371 ds.insignificance = 0.0 2372 2373 # The grid search size (the number of increments per dimension). 2374 ds.GRID_INC = 8 2375 2376 # The do clustering. 2377 ds.do_cluster = False 2378 2379 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2380 # The default value is 1e-25. 2381 ds.set_func_tol = 1e-9 2382 2383 # The maximum number of iterations. 2384 # The default value is 1e7. 2385 ds.set_max_iter = 1000 2386 2387 # The verbosity level. 2388 ds.verbosity = 1 2389 2390 # The rel_change WARNING level. 2391 ds.rel_change = 0.05 2392 2393 # The plot_curves. 2394 ds.plot_curves = False 2395 2396 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2397 ds.sherekhan_input = False 2398 2399 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2400 ds.opendx = False 2401 2402 # The set r2eff err. 2403 ds.r2eff_err = 0.1 2404 2405 # The print result info. 2406 ds.print_res = False 2407 2408 # Execute the script. 2409 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2410 2411 cur_spins = ds.data[2] 2412 # Compare results. 2413 for i in range(len(cur_spins)): 2414 res_name, res_num, spin_name, params = cur_spins[i] 2415 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2416 cur_spin = return_spin(cur_spin_id) 2417 2418 grid_params = ds.grid_results[i][3] 2419 min_params = ds.min_results[i][3] 2420 # Now read the parameters. 2421 print("For spin: '%s'"%cur_spin_id) 2422 for mo_param in cur_spin.params: 2423 # The R2 is a dictionary, depending on spectrometer frequency. 2424 if isinstance(getattr(cur_spin, mo_param), dict): 2425 grid_r2 = grid_params[mo_param] 2426 min_r2 = min_params[mo_param] 2427 set_r2 = params[mo_param] 2428 for key, val in set_r2.items(): 2429 grid_r2_frq = grid_r2[key] 2430 min_r2_frq = min_r2[key] 2431 set_r2_frq = set_r2[key] 2432 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2433 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2434 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2435 if rel_change > ds.rel_change: 2436 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2437 print("###################################") 2438 2439 ## Make test on R2. 2440 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2441 else: 2442 grid_val = grid_params[mo_param] 2443 min_val = min_params[mo_param] 2444 set_val = params[mo_param] 2445 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2446 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2447 if rel_change > ds.rel_change: 2448 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2449 print("###################################") 2450 2451 ## Make test on parameters. 2452 if mo_param == 'dw': 2453 self.assertAlmostEqual(set_val/10, min_val/10, 5) 2454 elif mo_param == 'kex': 2455 self.assertAlmostEqual(set_val/1000, min_val/1000, 5) 2456 elif mo_param == 'pA': 2457 self.assertAlmostEqual(set_val, min_val, 6)
2458 2459
2461 """Test synthetic cpmg data. For CR72 with small noise and cluster. 2462 2463 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2464 """ 2465 2466 # Reset. 2467 #self.interpreter.reset() 2468 2469 ## Set Experiments. 2470 model_create = 'NS CPMG 2-site 3D' 2471 #model_create = 'NS CPMG 2-site expanded' 2472 model_analyse = 'CR72' 2473 2474 # Exp 1 2475 sfrq_1 = 599.8908617*1E6 2476 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2477 time_T2_1 = 0.06 2478 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2479 r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2480 #r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2481 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2482 2483 sfrq_2 = 499.8908617*1E6 2484 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2485 time_T2_2 = 0.05 2486 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2487 r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2488 #r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2489 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2490 2491 # Collect all exps 2492 exps = [exp_1, exp_2] 2493 2494 spins = [ 2495 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ], 2496 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.99, 'dw': 1.} ] 2497 ] 2498 2499 # Collect the data to be used. 2500 ds.data = [model_create, model_analyse, spins, exps] 2501 2502 # The tmp directory. None is the local directory. 2503 ds.tmpdir = ds.tmpdir 2504 2505 # The results directory. None is the local directory. 2506 #ds.resdir = None 2507 ds.resdir = ds.tmpdir 2508 2509 # Do r20_from_min_r2eff ?. 2510 ds.r20_from_min_r2eff = True 2511 2512 # Remove insignificant level. 2513 ds.insignificance = 0.0 2514 2515 # The grid search size (the number of increments per dimension). 2516 ds.GRID_INC = 13 2517 2518 # The do clustering. 2519 ds.do_cluster = True 2520 2521 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2522 # The default value is 1e-25. 2523 ds.set_func_tol = 1e-8 2524 2525 # The maximum number of iterations. 2526 # The default value is 1e7. 2527 ds.set_max_iter = 10000 2528 2529 # The verbosity level. 2530 ds.verbosity = 1 2531 2532 # The rel_change WARNING level. 2533 ds.rel_change = 0.05 2534 2535 # The plot_curves. 2536 ds.plot_curves = False 2537 2538 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2539 ds.sherekhan_input = False 2540 2541 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2542 ds.opendx = False 2543 2544 # The set r2eff err. 2545 ds.r2eff_err = 0.1 2546 2547 # The print result info. 2548 ds.print_res = False 2549 2550 # Execute the script. 2551 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2552 2553 cur_spins = ds.data[2] 2554 # Compare results. 2555 for i in range(len(cur_spins)): 2556 res_name, res_num, spin_name, params = cur_spins[i] 2557 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2558 cur_spin = return_spin(cur_spin_id) 2559 2560 grid_params = ds.grid_results[i][3] 2561 2562 # Extract the clust results. 2563 min_params = ds.clust_results[i][3] 2564 # Now read the parameters. 2565 print("For spin: '%s'"%cur_spin_id) 2566 for mo_param in cur_spin.params: 2567 # The R2 is a dictionary, depending on spectrometer frequency. 2568 if isinstance(getattr(cur_spin, mo_param), dict): 2569 grid_r2 = grid_params[mo_param] 2570 min_r2 = min_params[mo_param] 2571 set_r2 = params[mo_param] 2572 for key, val in set_r2.items(): 2573 grid_r2_frq = grid_r2[key] 2574 min_r2_frq = min_r2[key] 2575 set_r2_frq = set_r2[key] 2576 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2577 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2578 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2579 if rel_change > ds.rel_change: 2580 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2581 print("###################################") 2582 2583 ## Make test on R2. 2584 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2585 else: 2586 grid_val = grid_params[mo_param] 2587 min_val = min_params[mo_param] 2588 set_val = params[mo_param] 2589 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2590 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2591 if rel_change > ds.rel_change: 2592 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2593 print("###################################") 2594 2595 ## Make test on parameters. 2596 if mo_param == 'dw': 2597 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2598 elif mo_param == 'kex': 2599 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2600 elif mo_param == 'pA': 2601 self.assertAlmostEqual(set_val, min_val, 2)
2602 2603
2605 """Test synthetic cpmg data, calling the dx.map function with one or two points. 2606 2607 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2608 """ 2609 2610 # Reset. 2611 #self.interpreter.reset() 2612 2613 ## Set Experiments. 2614 model_create = MODEL_NS_CPMG_2SITE_EXPANDED 2615 model_analyse = 'CR72' 2616 # Exp 1 2617 sfrq_1 = 599.8908617*1E6 2618 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2619 time_T2_1 = 0.06 2620 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2621 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2622 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2623 2624 sfrq_2 = 499.8908617*1E6 2625 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2626 time_T2_2 = 0.05 2627 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2628 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2629 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2630 2631 # Collect all exps 2632 exps = [exp_1, exp_2] 2633 2634 spins = [ 2635 ['Ala', 1, 'N', {'r2': {r20_key_1:2, r20_key_2:2}, 'r2a': {r20_key_1:2, r20_key_2:2}, 'r2b': {r20_key_1:2, r20_key_2:2}, 'kex': 1000, 'pA': 0.99, 'dw': 2} ] 2636 ] 2637 2638 # Collect the data to be used. 2639 ds.data = [model_create, model_analyse, spins, exps] 2640 2641 # The tmp directory. None is the local directory. 2642 ds.tmpdir = ds.tmpdir 2643 2644 # The results directory. None is the local directory. 2645 #ds.resdir = None 2646 ds.resdir = ds.tmpdir 2647 2648 # Do r20_from_min_r2eff ?. 2649 ds.r20_from_min_r2eff = True 2650 2651 # Remove insignificant level. 2652 ds.insignificance = 0.0 2653 2654 # The grid search size (the number of increments per dimension). 2655 ds.GRID_INC = None 2656 2657 # The do clustering. 2658 ds.do_cluster = False 2659 2660 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2661 # The default value is 1e-25. 2662 ds.set_func_tol = 1e-9 2663 2664 # The maximum number of iterations. 2665 # The default value is 1e7. 2666 ds.set_max_iter = 1000 2667 2668 # The verbosity level. 2669 ds.verbosity = 1 2670 2671 # The rel_change WARNING level. 2672 ds.rel_change = 0.05 2673 2674 # The plot_curves. 2675 ds.plot_curves = False 2676 2677 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2678 ds.sherekhan_input = False 2679 2680 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2681 ds.opendx = False 2682 2683 # The set r2eff err. 2684 ds.r2eff_err = 0.1 2685 2686 # The print result info. 2687 ds.print_res = False 2688 2689 # Execute the script. 2690 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2691 2692 # Get the spins. 2693 cur_spins = ds.data[2] 2694 2695 # First switch pipe, since dx.map will go through parameters and end up a "bad" place. :-) 2696 ds.pipe_name_MODEL_MAP = "%s_%s_map"%(ds.pipe_name, model_analyse) 2697 self.interpreter.pipe.copy(pipe_from=ds.pipe_name, pipe_to=ds.pipe_name_MODEL_MAP, bundle_to = ds.pipe_bundle) 2698 self.interpreter.pipe.switch(pipe_name=ds.pipe_name_MODEL_MAP) 2699 2700 # Copy R2eff, but not the original parameters 2701 self.interpreter.value.copy(pipe_from=ds.pipe_name_r2eff, pipe_to=ds.pipe_name_MODEL_MAP, param='r2eff') 2702 2703 # Then select model. 2704 self.interpreter.relax_disp.select_model(model=model_analyse) 2705 2706 # Define dx.map settings. 2707 ds.dx_inc = 4 2708 ds.dx_params = ['dw', 'pA', 'kex'] 2709 2710 res_name, res_num, spin_name, params = cur_spins[0] 2711 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2712 cur_spin = return_spin(cur_spin_id) 2713 2714 print("Params for dx map is") 2715 print(ds.dx_params) 2716 print("Point param for dx map is") 2717 print(ds.dx_set_val) 2718 cur_model = model_analyse.replace(' ', '_') 2719 file_name_map = "%s_map%s" % (cur_model, cur_spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 2720 file_name_point = "%s_point%s" % (cur_model, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 2721 self.interpreter.dx.map(params=ds.dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=ds.dx_inc, lower=None, upper=None, axis_incs=10, file_prefix=file_name_map, dir=ds.resdir, point=[ds.dx_set_val, ds.dx_clust_val], point_file=file_name_point) 2722 2723 ## Check for file creation 2724 # Set filepaths. 2725 map_cfg = ds.tmpdir+sep+file_name_map+".cfg" 2726 map_net = ds.tmpdir+sep+file_name_map+".net" 2727 map_general = ds.tmpdir+sep+file_name_map+".general" 2728 2729 point_general = ds.tmpdir+sep+file_name_point+".general" 2730 point_point = ds.tmpdir+sep+file_name_point 2731 2732 # Test the files exists. 2733 self.assert_(access(map_cfg, F_OK)) 2734 self.assert_(access(map_net, F_OK)) 2735 self.assert_(access(map_general, F_OK)) 2736 self.assert_(access(point_general, F_OK)) 2737 self.assert_(access(point_point, F_OK)) 2738 2739 # Open the files for testing. 2740 # Check the cfg file. 2741 print("\nChecking the dx map .cfg file.") 2742 res_file = [ 2743 '//'+"\n", 2744 '//'+"\n", 2745 '// time: Thu May 8 18:55:31 2014'+"\n", 2746 '//'+"\n", 2747 '// version: 3.2.0 (format), 4.3.2 (DX)'+"\n", 2748 '//'+"\n", 2749 '//'+"\n", 2750 '// panel[0]: position = (0.0164,0.0000), size = 0.2521x0.1933, startup = 1, devstyle = 1'+"\n", 2751 '// title: value = Control Panel'+"\n", 2752 '//'+"\n", 2753 '// workspace: width = 251, height = 142'+"\n", 2754 '// layout: snap = 0, width = 50, height = 50, align = NN'+"\n", 2755 '//'+"\n", 2756 '// interactor Selector[1]: num_components = 1, value = 1 '+"\n", 2757 '// selections: maximum = 2, current = 0 '+"\n", 2758 '// option[0]: name = "Colour", value = 1'+"\n", 2759 '// option[1]: name = "Grey", value = 2'+"\n", 2760 '// instance: panel = 0, x = 81, y = 6, style = Scrolled List, vertical = 1, size = 170x136'+"\n", 2761 '// label: value = Colour Selector'+"\n", 2762 '//'+"\n", 2763 '// node Image[3]:'+"\n", 2764 '// title: value = Surface'+"\n", 2765 '// depth: value = 24'+"\n", 2766 '// window: position = (0.0000,0.0400), size = 0.9929x0.9276'+"\n", 2767 ] 2768 file = open(map_cfg, 'r') 2769 lines = file.readlines() 2770 file.close() 2771 for i in range(len(res_file)): 2772 # Skip time point 2773 if i == 2: 2774 continue 2775 self.assertEqual(res_file[i], lines[i]) 2776 2777 print("\nChecking the dx map .general file.") 2778 res_file = [ 2779 'file = CR72_map_1_N'+"\n", 2780 'grid = 5 x 5 x 5'+"\n", 2781 'format = ascii'+"\n", 2782 'interleaving = field'+"\n", 2783 'majority = row'+"\n", 2784 'field = data'+"\n", 2785 'structure = scalar'+"\n", 2786 'type = float'+"\n", 2787 'dependency = positions'+"\n", 2788 'positions = regular, regular, regular, 0, 1, 0, 1, 0, 1'+"\n", 2789 ''+"\n", 2790 'end'+"\n", 2791 ] 2792 file = open(map_general, 'r') 2793 lines = file.readlines() 2794 file.close() 2795 for i in range(len(res_file)): 2796 # Skip time point 2797 #if i == 2: 2798 # continue 2799 self.assertEqual(res_file[i], lines[i]) 2800 2801 print("\nChecking the dx point .general file.") 2802 res_file = [ 2803 'file = CR72_point_1_N'+"\n", 2804 'points = 2'+"\n", 2805 'format = ascii'+"\n", 2806 'interleaving = field'+"\n", 2807 'field = locations, field0'+"\n", 2808 'structure = 3-vector, scalar'+"\n", 2809 'type = float, float'+"\n", 2810 ''+"\n", 2811 'end'+"\n", 2812 ] 2813 file = open(point_general, 'r') 2814 lines = file.readlines() 2815 file.close() 2816 for i in range(len(res_file)): 2817 # Skip time point 2818 #if i == 2: 2819 # continue 2820 self.assertEqual(res_file[i], lines[i]) 2821 2822 print("\nChecking the dx point point file.") 2823 res_file = [ 2824 '0.8 3.92 0.39964 1'+"\n", 2825 '0.76981 3.9169 0.41353 1'+"\n", 2826 ] 2827 file = open(point_point, 'r') 2828 lines = file.readlines() 2829 file.close() 2830 for i in range(len(res_file)): 2831 # Skip time point 2832 #if i == 2: 2833 # continue 2834 self.assertEqual(res_file[i], lines[i])
2835 2836
2838 """Test the curve type detection using the Dr. Flemming Hansen's CPMG fixed time test data.""" 2839 2840 # Reset. 2841 self.interpreter.reset() 2842 2843 # Load the base data. 2844 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 2845 self.interpreter.state.load(data_path+sep+'r2eff_values') 2846 2847 # The type. 2848 curve_type = get_curve_type(id='500_133.33.in') 2849 self.assertEqual(curve_type, 'fixed time')
2850 2851
2852 - def test_curve_type_r1rho_exponential(self, model=None):
2853 """Test the curve type detection using the 'M61' exponential test data.""" 2854 2855 # Reset. 2856 self.interpreter.reset() 2857 2858 # Load the base data. 2859 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_on_res_m61' 2860 self.interpreter.state.load(data_path+sep+'r2eff_values') 2861 2862 # The type. 2863 curve_type = get_curve_type(id='nu_2000_ncyc9') 2864 self.assertEqual(curve_type, 'exponential')
2865 2866
2867 - def test_curve_type_r1rho_fixed_time(self, model=None):
2868 """Test the curve type detection using the 'TP02' fixed time test data.""" 2869 2870 # Reset. 2871 self.interpreter.reset() 2872 2873 # Load the base data. 2874 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 2875 self.interpreter.state.load(data_path+sep+'r2eff_values') 2876 2877 # The type. 2878 curve_type = get_curve_type(id='nu_1000.0_500MHz') 2879 self.assertEqual(curve_type, 'fixed time')
2880 2881
2882 - def test_dpl94_data_to_dpl94(self):
2883 """Test the relaxation dispersion 'DPL94' model curve fitting to fixed time synthetic data.""" 2884 2885 # Fixed time variable. 2886 ds.fixed = True 2887 2888 # Execute the script. 2889 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_dpl94.py') 2890 2891 # The original parameters. 2892 i0 = [100000.0, 20000.0] 2893 r1rho_prime = [2.25, 24.0] 2894 pA = 0.7 2895 kex = 1000.0 2896 delta_omega = [1.0, 2.0] 2897 phi_ex = [] 2898 for i in range(2): 2899 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 2900 2901 # Switch to the 'DPL94' model data pipe, then check for each spin. 2902 self.interpreter.pipe.switch('DPL94 - relax_disp') 2903 spin_index = 0 2904 for spin, spin_id in spin_loop(return_id=True): 2905 # Printout. 2906 print("\nSpin %s." % spin_id) 2907 2908 # Check the fitted parameters. 2909 self.assertAlmostEqual(spin.r2['R1rho - 800.00000000 MHz']/10, r1rho_prime[spin_index]/10, 2) 2910 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 2911 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 2912 2913 # Increment the spin index. 2914 spin_index += 1
2915 2916
2917 - def test_estimate_r2eff_err(self):
2918 """Test the user function for estimating R2eff errors from exponential curve fitting. 2919 2920 This follows Task 7822. 2921 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 2922 2923 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 2924 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 2925 """ 2926 2927 # Cluster residues 2928 cluster_ids = [ 2929 ":13@N", 2930 ":15@N", 2931 ":16@N", 2932 ":25@N", 2933 ":26@N", 2934 ":28@N", 2935 ":39@N", 2936 ":40@N", 2937 ":41@N", 2938 ":43@N", 2939 ":44@N", 2940 ":45@N", 2941 ":49@N", 2942 ":52@N", 2943 ":53@N"] 2944 2945 # Load the data. 2946 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 2947 2948 # The dispersion models. 2949 MODELS = [MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 2950 2951 # The grid search size (the number of increments per dimension). 2952 GRID_INC = None 2953 2954 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 2955 MC_NUM = 3 2956 2957 # Model selection technique. 2958 MODSEL = 'AIC' 2959 2960 # Execute the auto-analysis (fast). 2961 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 2962 OPT_FUNC_TOL = 1e-25 2963 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 2964 OPT_MAX_ITERATIONS = 10000000 2965 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 2966 2967 result_dir_name = ds.tmpdir 2968 2969 # Make all spins free 2970 for curspin in cluster_ids: 2971 self.interpreter.relax_disp.cluster('free spins', curspin) 2972 # Shut them down 2973 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 2974 2975 # Select only a subset of spins for global fitting 2976 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 2977 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 2978 2979 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 2980 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 2981 2982 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 2983 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 2984 2985 # Set the model. 2986 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 2987 2988 # Check if intensity errors have already been calculated. 2989 check_intensity_errors() 2990 2991 # Do a grid search. 2992 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 2993 2994 # Minimise. 2995 self.interpreter.minimise.execute(min_algor='Newton', constraints=False, verbosity=1) 2996 2997 # Estimate R2eff errors. 2998 self.interpreter.relax_disp.r2eff_err_estimate() 2999 3000 r1_fit = True 3001 3002 # Run the analysis. 3003 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3004 3005 # Verify the data. 3006 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3007 3008
3010 """Test the user function for estimating R2eff errors from exponential curve fitting, via the auto_analyses menu. 3011 3012 This follows Task 7822. 3013 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3014 3015 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3016 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3017 """ 3018 3019 # Cluster residues 3020 cluster_ids = [ 3021 ":13@N", 3022 ":15@N", 3023 ":16@N", 3024 ":25@N", 3025 ":26@N", 3026 ":28@N", 3027 ":39@N", 3028 ":40@N", 3029 ":41@N", 3030 ":43@N", 3031 ":44@N", 3032 ":45@N", 3033 ":49@N", 3034 ":52@N", 3035 ":53@N"] 3036 3037 # Load the data. 3038 #self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3039 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 3040 3041 # Set pipe name, bundle and type. 3042 pipe_name = 'base pipe' 3043 pipe_bundle = 'relax_disp' 3044 pipe_type = 'relax_disp' 3045 3046 # Create the data pipe. 3047 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 3048 3049 file = data_path + '1_setup_r1rho_GUI.py' 3050 self.interpreter.script(file=file, dir=None) 3051 3052 # The dispersion models. 3053 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3054 3055 # The grid search size (the number of increments per dimension). 3056 GRID_INC = None 3057 3058 # The number of Monte Carlo simulations to be used for error analysis for exponential curve fitting of R2eff. 3059 # When set to minus 1, estimation of the errors will be extracted from the covariance matrix. 3060 # This is HIGHLY likely to be wrong, but can be used in an initial test fase. 3061 EXP_MC_NUM = -1 3062 3063 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3064 MC_NUM = 3 3065 3066 # Model selection technique. 3067 MODSEL = 'AIC' 3068 3069 # Execute the auto-analysis (fast). 3070 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3071 OPT_FUNC_TOL = 1e-25 3072 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3073 OPT_MAX_ITERATIONS = 10000000 3074 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3075 3076 # Make all spins free 3077 #for curspin in cluster_ids: 3078 # self.interpreter.relax_disp.cluster('free spins', curspin) 3079 # # Shut them down 3080 # self.interpreter.deselect.spin(spin_id=curspin, boolean='OR', change_all=False) 3081 3082 # Make all spins free 3083 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 3084 3085 # Select only a subset of spins for global fitting 3086 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3087 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3088 3089 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3090 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3091 3092 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3093 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3094 3095 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3096 print(spin_id) 3097 3098 result_dir_name = self.tmpdir 3099 r1_fit = True 3100 3101 # Run the analysis. 3102 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=EXP_MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3103 3104 # Verify the data. 3105 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3106 3107
3109 """Test the user function for estimating R2eff and associated errors for exponential curve fitting with different methods. 3110 This is compared with a run where erros are estimated by 2000 Monte Carlo simulations. 3111 3112 This follows Task 7822. 3113 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3114 3115 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3116 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3117 3118 NOTE: The difference in the methods was due to a bug in relax! 3119 U{bug #22554<https://gna.org/bugs/index.php?22554>}. The distribution of intensity with errors in Monte-Carlo simulations are markedly more narrow than expected. 3120 3121 This dataset is old, and includes 2000 Monte-Carlo simulations, which is performed wrong. 3122 """ 3123 3124 # Define data path. 3125 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 3126 3127 # Create pipe. 3128 self.interpreter.pipe.create('MC_2000', 'relax_disp') 3129 3130 # Read results for 2000 MC simulations. 3131 self.interpreter.results.read(prev_data_path + sep + 'results') 3132 3133 # Start dic. 3134 my_dic = {} 3135 param_key_list = [] 3136 3137 # Do boot strapping ? 3138 do_boot = True 3139 if do_boot: 3140 min_algor = 'Newton' 3141 min_options = () 3142 sim_boot = 200 3143 scaling_list = [1.0, 1.0] 3144 3145 # First check sim values. 3146 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3147 # Add key to dic. 3148 my_dic[spin_id] = {} 3149 3150 # Loop over sim. 3151 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3152 # Loop over all exp type. 3153 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3154 # Generate the param_key. 3155 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3156 r2eff_sim_point = r2eff_sim[param_key] 3157 i0_sim_point = cur_spin.r2eff_sim[i][param_key] 3158 3159 # Assert point are higher than 0.0. 3160 #point_info = "r2eff=%3.2f i0=%3.2f, at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f, at sim index %i." % (r2eff_sim_point, i0_sim_point, frq/1E6, offset, point, i) 3161 #print(point_info) 3162 self.assert_(r2eff_sim_point > 0.0) 3163 self.assert_(i0_sim_point > 0.0) 3164 3165 # Get the data. 3166 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3167 # Generate spin string. 3168 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3169 3170 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3171 # Generate the param_key. 3172 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3173 3174 # Loop over all sim, and collect data. 3175 r2eff_sim_l = [] 3176 i0_sim_l = [] 3177 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3178 i0_sim = cur_spin.i0_sim[i] 3179 3180 r2eff_sim_i = r2eff_sim[param_key] 3181 r2eff_sim_l.append(r2eff_sim_i) 3182 i0_sim_i = i0_sim[param_key] 3183 i0_sim_l.append(i0_sim_i) 3184 3185 # Take the standard deviation of all values. 3186 r2eff_sim_err = std(asarray(r2eff_sim_l), ddof=1) 3187 i0_sim_err = std(asarray(i0_sim_l), ddof=1) 3188 3189 # Append key. 3190 param_key_list.append(param_key) 3191 3192 # Add key to dic. 3193 my_dic[spin_id][param_key] = {} 3194 3195 # Get the value. 3196 r2eff = getattr(cur_spin, 'r2eff')[param_key] 3197 r2eff_err = getattr(cur_spin, 'r2eff_err')[param_key] 3198 i0 = getattr(cur_spin, 'i0')[param_key] 3199 i0_err = getattr(cur_spin, 'i0_err')[param_key] 3200 3201 # Save to dic. 3202 my_dic[spin_id][param_key]['r2eff'] = r2eff 3203 my_dic[spin_id][param_key]['r2eff_err'] = r2eff_err 3204 my_dic[spin_id][param_key]['i0'] = i0 3205 my_dic[spin_id][param_key]['i0_err'] = i0_err 3206 my_dic[spin_id][param_key]['r2eff_err_sim'] = r2eff_sim_err 3207 my_dic[spin_id][param_key]['i0_err_sim'] = i0_sim_err 3208 3209 # Assert values are equal 3210 self.assertAlmostEqual(r2eff_sim_err, r2eff_err) 3211 self.assertAlmostEqual(i0_sim_err, i0_err) 3212 3213 if do_boot: 3214 values = [] 3215 errors = [] 3216 times = [] 3217 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 3218 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 3219 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 3220 times.append(time) 3221 3222 # Convert to numpy array. 3223 values = asarray(values) 3224 errors = asarray(errors) 3225 times = asarray(times) 3226 3227 R_m_sim_l = [] 3228 I0_m_sim_l = [] 3229 for j in range(sim_boot): 3230 if j in range(0, 100000, 100): 3231 print("Simulation %i"%j) 3232 # Start minimisation. 3233 3234 # Produce errors 3235 I_err = [] 3236 for j, error in enumerate(errors): 3237 I_error = gauss(values[j], error) 3238 I_err.append(I_error) 3239 # Convert to numpy array. 3240 I_err = asarray(I_err) 3241 3242 x0 = [r2eff, i0] 3243 setup(num_params=len(x0), num_times=len(times), values=I_err, sd=errors, relax_times=times, scaling_matrix=scaling_list) 3244 3245 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=func, dfunc=dfunc, d2func=d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, full_output=True, print_flag=0) 3246 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 3247 R_m_sim_l.append(R_m_sim_j) 3248 I0_m_sim_l.append(I0_m_sim_j) 3249 3250 # Get stats on distribution. 3251 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 3252 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 3253 my_dic[spin_id][param_key]['r2eff_err_boot'] = sigma_R_sim 3254 my_dic[spin_id][param_key]['i0_err_boot'] = sigma_I0_sim 3255 3256 3257 # A new data pipe. 3258 self.interpreter.pipe.copy(pipe_from='MC_2000', pipe_to='r2eff_est') 3259 self.interpreter.pipe.switch(pipe_name='r2eff_est') 3260 3261 # Delete old errors. 3262 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3263 delattr(cur_spin, 'r2eff_err') 3264 delattr(cur_spin, 'i0_err') 3265 3266 # Set the model. 3267 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3268 3269 # Estimate R2eff and errors. 3270 self.interpreter.relax_disp.r2eff_err_estimate(verbosity=0) 3271 3272 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3273 # Generate spin string. 3274 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3275 3276 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3277 # Generate the param_key. 3278 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3279 3280 # Get the value. 3281 r2eff_est = getattr(cur_spin, 'r2eff')[param_key] 3282 r2eff_err_est = getattr(cur_spin, 'r2eff_err')[param_key] 3283 i0_est = getattr(cur_spin, 'i0')[param_key] 3284 i0_err_est = getattr(cur_spin, 'i0_err')[param_key] 3285 3286 # Get from dic. 3287 r2eff = my_dic[spin_id][param_key]['r2eff'] 3288 r2eff_err = my_dic[spin_id][param_key]['r2eff_err'] 3289 i0 = my_dic[spin_id][param_key]['i0'] 3290 i0_err = my_dic[spin_id][param_key]['i0_err'] 3291 r2eff_sim_err = my_dic[spin_id][param_key]['r2eff_err_sim'] 3292 i0_sim_err = my_dic[spin_id][param_key]['i0_err_sim'] 3293 3294 if do_boot: 3295 r2eff_boot_err = my_dic[spin_id][param_key]['r2eff_err_boot'] 3296 i0_boot_err = my_dic[spin_id][param_key]['i0_err_boot'] 3297 else: 3298 r2eff_boot_err = 0.0 3299 i0_boot_err = 0.0 3300 3301 print("%s at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f." % (exp_type, frq/1E6, offset, point) ) 3302 print("r2eff=%3.3f/%3.3f r2eff_err=%3.4f/%3.4f/%3.4f/%3.4f" % (r2eff, r2eff_est, r2eff_err, r2eff_err_est, r2eff_sim_err, r2eff_boot_err) ), 3303 print("i0=%3.3f/%3.3f i0_err=%3.4f/%3.4f/%3.4f/%3.4f\n" % (i0, i0_est, i0_err, i0_err_est, i0_sim_err, i0_boot_err) ) 3304 3305 3306 # Now do it manually. 3307 estimate_r2eff(method='scipy.optimize.leastsq') 3308 3309 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=False) 3310 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=True) 3311 3312 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=False) 3313 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=True) 3314 3315 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=False) 3316 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=True) 3317 3318 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=False) 3319 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=True) 3320 3321 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=False) 3322 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=True)
3323 3324 3325
3326 - def test_exp_fit(self):
3327 """Test the relaxation dispersion 'exp_fit' model curve fitting.""" 3328 3329 # Execute the script. 3330 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'exp_fit.py') 3331 3332 # The original exponential curve parameters. 3333 res_data = [ 3334 [15., 10., 20000., 25000.], 3335 [12., 11., 50000., 51000.], 3336 [17., 9., 100000., 96000.] 3337 ] 3338 3339 # List of parameters which do not belong to the model. 3340 blacklist = ['cpmg_frqs', 'r2', 'rex', 'kex', 'r2a', 'k_AB', 'dw'] 3341 3342 # Checks for each residue. 3343 for i in range(len(res_data)): 3344 # Printout. 3345 print("\nResidue number %s." % (i+1)) 3346 3347 # Check the fitted parameters. 3348 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_1000.000'], res_data[i][0], places=2) 3349 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_2000.000'], res_data[i][1], places=2) 3350 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_1000.000']/10000, res_data[i][2]/10000, places=3) 3351 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_2000.000']/10000, res_data[i][3]/10000, places=3) 3352 3353 # Check the simulation errors. 3354 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_1000.000'] < 5.0) 3355 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_2000.000'] < 5.0) 3356 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_1000.000']/10000 < 5.0) 3357 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_2000.000']/10000 < 5.0) 3358 3359 # Check that certain parameters are not present. 3360 for param in blacklist: 3361 print("\tChecking for the absence of the '%s' parameter." % param) 3362 self.assert_(not hasattr(cdp.mol[0].res[i].spin[0], param)) 3363 3364 # Check the clustering information. 3365 self.assert_(hasattr(cdp, 'clustering')) 3366 keys = ['free spins', 'cluster'] 3367 for key in keys: 3368 self.assert_(key in cdp.clustering) 3369 self.assert_('test' not in cdp.clustering) 3370 self.assertEqual(cdp.clustering['free spins'], [':2@N']) 3371 self.assertEqual(cdp.clustering['cluster'], [':1@N', ':3@N'])
3372 3373
3374 - def test_finite_value(self):
3375 """Test return from C code, when parameters are wrong. This can happen, if minfx takes a wrong step.""" 3376 3377 times = array([ 0.7, 1., 0.8, 0.4, 0.9]) 3378 I = array([ 476.76174875, 372.43328777, 454.20339981, 656.87936253, 419.16726341]) 3379 errors = array([ 9.48032653, 11.34093541, 9.35149017, 10.84867928, 12.17590736]) 3380 3381 scaling_list = [1.0, 1.0] 3382 setup(num_params=2, num_times=len(times), values=I, sd=errors, relax_times=times, scaling_matrix=scaling_list) 3383 3384 R = - 500. 3385 I0 = 1000. 3386 params = [R, I0] 3387 3388 chi2 = func(params) 3389 3390 print("The chi2 value returned from C-code for R=%3.2f and I0=%3.2f, then chi2=%3.2f"%(R, I0, chi2)) 3391 self.assertNotEqual(chi2, inf)
3392 3393
3394 - def test_hansen_catia_input(self):
3395 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CATIA. 3396 3397 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3398 """ 3399 3400 # Load the R2eff results file. 3401 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 3402 self.interpreter.results.read(file_name) 3403 self.interpreter.deselect.spin(':4') 3404 3405 # The spin isotopes. 3406 self.interpreter.spin.isotope("15N") 3407 3408 # Generate the input files. 3409 self.interpreter.relax_disp.catia_input(dir=ds.tmpdir, force=True) 3410 3411 # Check the r2eff set files. 3412 print("\nChecking the R2eff input set files.") 3413 files = ['data_set_500.inp', 'data_set_500.inp'] 3414 for file in files: 3415 self.assert_(access(ds.tmpdir+sep+file, F_OK)) 3416 data_set_500 = [ 3417 "ID=500\n", 3418 "Sfrq = 500\n", 3419 "Temperature = 0.0\n", 3420 "Nucleus = N15\n", 3421 "Couplednucleus = H1\n", 3422 "Time_equil = 0.0\n", 3423 "Pwx_cp = 0.0\n", 3424 "Taub = 0.0\n", 3425 "Time_T2 = 0.03\n", 3426 "Xcar = 0.0\n", 3427 "Seqfil = CW_CPMG\n", 3428 "Minerror = (2.%;0.5/s)\n", 3429 "Basis = (Iph_7)\n", 3430 "Format = (0;1;2)\n", 3431 "DataDirectory = /tmp/tmpNjOGNG/input_r2eff\n", 3432 "Data = (\n", 3433 " [70N;spin_70_N_500.cpmg];\n", 3434 " [71N;spin_71_N_500.cpmg];\n", 3435 ")\n", 3436 ] 3437 file = open(ds.tmpdir+sep+files[0]) 3438 lines = file.readlines() 3439 file.close() 3440 for i in range(len(data_set_500)): 3441 # Skip the data directory, as this is a random file name. 3442 if i == 14: 3443 continue 3444 3445 self.assertEqual(data_set_500[i], lines[i]) 3446 3447 # Check the r2eff files. 3448 print("\nChecking the R2eff input files.") 3449 files = ['spin_70_N_500.cpmg', 'spin_70_N_800.cpmg', 'spin_71_N_500.cpmg', 'spin_71_N_800.cpmg'] 3450 for file in files: 3451 self.assert_(access(ds.tmpdir+sep+'input_r2eff'+sep+file, F_OK)) 3452 spin_70_N_500 = [ 3453 "# nu_cpmg(Hz) R2(1/s) Esd(R2)\n", 3454 " 66.666600000000003 16.045540885533605 0.310924686180635\n", 3455 " 133.333300000000008 14.877924861181727 0.303217270671013\n", 3456 " 200.000000000000000 14.357820247260586 0.299894424543361\n", 3457 " 266.666600000000017 12.664494620416516 0.289532060485796\n", 3458 " 333.333300000000008 12.363204802467891 0.287759631749322\n", 3459 " 400.000000000000000 11.092532381134513 0.280514035409862\n", 3460 " 466.666600000000017 10.566090057649893 0.277618625949722\n", 3461 " 533.333300000000008 9.805806894657803 0.273544382200754\n", 3462 " 600.000000000000000 9.564300692201730 0.272276309984954\n", 3463 " 666.666600000000017 9.015633750407980 0.269441511838159\n", 3464 " 733.333300000000008 8.607764958055581 0.267375134391053\n", 3465 " 800.000000000000000 8.279997179221338 0.265739551961997\n", 3466 " 866.666600000000017 8.474535940963516 0.266707642726566\n", 3467 " 933.333300000000008 8.158972897365194 0.265141210539941\n", 3468 "1000.000000000000000 7.988630509501972 0.264304105548559\n", 3469 ] 3470 file = open(ds.tmpdir+sep+'input_r2eff'+sep+files[0]) 3471 lines = file.readlines() 3472 file.close() 3473 for i in range(len(lines)): 3474 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 3475 for i in range(len(spin_70_N_500)): 3476 self.assertEqual(spin_70_N_500[i], lines[i]) 3477 3478 # Check the main file. 3479 print("\nChecking the main CATIA execution file.") 3480 main_file = [ 3481 "ReadDataset(data_set_500.inp)\n", 3482 "ReadDataset(data_set_800.inp)\n", 3483 "ReadParam_Global(ParamGlobal.inp)\n", 3484 "ReadParam_Local(ParamSet1.inp)\n", 3485 "\n", 3486 "FreeLocalParam(all;Omega;false)\n", 3487 "FreeLocalParam(all;R1iph_500;false)\n", 3488 "FreeLocalParam(all;R1iph_800;false)\n", 3489 "\n", 3490 "Minimize(print=y;tol=1e-25;maxiter=10000000)\n", 3491 "\n", 3492 "PrintParam(output/GlobalParam.fit;global)\n", 3493 "PrintParam(output/DeltaOmega.fit;DeltaO)\n", 3494 "PrintData(output/)\n", 3495 "\n", 3496 "ChiSq(all;all)\n", 3497 "exit(0)\n" 3498 ] 3499 file = open("%s%sFit.catia" % (ds.tmpdir, sep)) 3500 lines = file.readlines() 3501 file.close() 3502 for i in range(len(main_file)): 3503 self.assertEqual(main_file[i], lines[i])
3504 3505
3507 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 3508 3509 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3510 """ 3511 3512 # Set the model. 3513 ds.models = [ 3514 MODEL_NOREX, 3515 MODEL_LM63, 3516 MODEL_CR72, 3517 MODEL_IT99 3518 ] 3519 3520 # Execute the script. 3521 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 3522 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 3523 3524 # The R20 keys. 3525 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3526 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3527 3528 # The 'No Rex' model checks. 3529 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 3530 spin70 = return_spin(":70") 3531 spin71 = return_spin(":71") 3532 print("\n\nOptimised parameters:\n") 3533 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3534 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3535 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3536 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3537 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 3538 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 3539 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 3540 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 3541 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 3542 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 3543 3544 # The 'LM63' model checks. 3545 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 3546 spin70 = return_spin(":70") 3547 spin71 = return_spin(":71") 3548 print("\n\nOptimised parameters:\n") 3549 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3550 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3551 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3552 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 3553 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3554 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3555 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 3556 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 3557 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 3558 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 3559 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 3560 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 3561 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 3562 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 3563 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 3564 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 3565 3566 # The 'CR72' model checks. 3567 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 3568 spin70 = return_spin(":70") 3569 spin71 = return_spin(":71") 3570 print("\n\nOptimised parameters:\n") 3571 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3572 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3573 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3574 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 3575 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 3576 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3577 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3578 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 3579 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 3580 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 3581 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 3582 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 3583 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 3584 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 3585 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 3586 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 3587 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 3588 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 3589 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3)
3590 3591
3593 """Test of the numeric model only dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 3594 3595 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3596 """ 3597 3598 # Set the model and numeric flag. 3599 ds.models = [ 3600 MODEL_NOREX, 3601 MODEL_CR72, 3602 MODEL_NS_CPMG_2SITE_EXPANDED 3603 ] 3604 ds.numeric_only = True 3605 3606 # Execute the script. 3607 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 3608 3609 # The R20 keys. 3610 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3611 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3612 3613 # The 'No Rex' model checks. 3614 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 3615 spin70 = return_spin(":70") 3616 spin71 = return_spin(":71") 3617 print("\n\nOptimised parameters:\n") 3618 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3619 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3620 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3621 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3622 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 3623 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 3624 self.assertAlmostEqual(spin70.chi2/10000, 8973.84810025761/10000, 3) 3625 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 3626 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 3627 self.assertAlmostEqual(spin71.chi2/10000, 3908.00127830003/10000, 3) 3628 3629 # The 'CR72' model checks. 3630 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 3631 spin70 = return_spin(":70") 3632 spin71 = return_spin(":71") 3633 print("\n\nOptimised parameters:\n") 3634 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3635 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3636 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3637 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 3638 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 3639 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3640 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3641 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 3642 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 3643 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 3644 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 3645 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 3646 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 3647 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 3648 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 3649 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 3650 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 3651 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 3652 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3) 3653 3654 # The 'NS CPMG 2-site expanded' model checks. 3655 self.interpreter.pipe.switch(pipe_name='NS CPMG 2-site expanded - relax_disp') 3656 spin70 = return_spin(":70") 3657 spin71 = return_spin(":71") 3658 print("\n\nOptimised parameters:\n") 3659 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3660 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3661 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3662 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 3663 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 3664 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3665 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3666 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95815351460902, 3) 3667 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39649535771294, 3) 3668 self.assertAlmostEqual(spin70.pA, 0.989701014493195, 3) 3669 self.assertAlmostEqual(spin70.dw, 5.67314464776128, 3) 3670 self.assertAlmostEqual(spin70.kex/10000, 1713.65380495429/10000, 3) 3671 self.assertAlmostEqual(spin70.chi2, 52.5106880917473, 3) 3672 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99889337382435, 3) 3673 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89822887466673, 3) 3674 self.assertAlmostEqual(spin71.pA, 0.986709050819695, 3) 3675 self.assertAlmostEqual(spin71.dw, 2.09238266766502, 2) 3676 self.assertAlmostEqual(spin71.kex/10000, 2438.27019901422/10000, 3) 3677 self.assertAlmostEqual(spin71.chi2, 15.1644906963987, 3) 3678 3679 # The final data pipe checks. 3680 self.interpreter.pipe.switch(pipe_name='final - relax_disp') 3681 spin70 = return_spin(":70") 3682 spin71 = return_spin(":71") 3683 self.assertEqual(spin70.model, 'NS CPMG 2-site expanded') 3684 self.assertEqual(spin71.model, 'NS CPMG 2-site expanded')
3685 3686
3688 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data (using the R2eff data directly instead of peak intensities). 3689 3690 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3691 """ 3692 3693 # Set the model. 3694 ds.models = [ 3695 MODEL_NOREX, 3696 MODEL_LM63, 3697 MODEL_CR72, 3698 MODEL_IT99 3699 ] 3700 3701 # Execute the script. 3702 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_r2eff_data.py') 3703 self.interpreter.state.save('analysis_r2eff', dir=ds.tmpdir, force=True) 3704 3705 # The R20 keys. 3706 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3707 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3708 3709 # The 'No Rex' model checks. 3710 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 3711 spin70 = return_spin(":70") 3712 spin71 = return_spin(":71") 3713 print("\n\nOptimised parameters:\n") 3714 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3715 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3716 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3717 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3718 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 3719 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 3720 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 3721 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 3722 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 3723 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 3724 3725 # The 'LM63' model checks. 3726 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 3727 spin70 = return_spin(":70") 3728 spin71 = return_spin(":71") 3729 print("\n\nOptimised parameters:\n") 3730 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3731 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3732 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3733 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 3734 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3735 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3736 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 3737 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 3738 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 3739 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 3740 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 3741 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 3742 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 3743 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 3744 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 3745 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 3746 3747 # The 'CR72' model checks. 3748 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 3749 spin70 = return_spin(":70") 3750 spin71 = return_spin(":71") 3751 print("\n\nOptimised parameters:\n") 3752 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3753 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3754 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3755 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 3756 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 3757 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3758 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3759 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 3760 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 3761 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 3762 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 3763 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 3764 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 3765 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00317154730225, 3) 3766 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797713541, 3) 3767 self.assertAlmostEqual(spin71.pA, 0.985922406429147, 3) 3768 self.assertAlmostEqual(spin71.dw, 2.00500965887772, 2) 3769 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579804/10000, 3) 3770 self.assertAlmostEqual(spin71.chi2, 15.6595374288635, 3)
3771 3772
3774 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data with parts missing. 3775 3776 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3777 """ 3778 3779 # Set the model. 3780 ds.models = [ 3781 MODEL_R2EFF, 3782 MODEL_NOREX, 3783 MODEL_CR72, 3784 MODEL_NS_CPMG_2SITE_EXPANDED 3785 ] 3786 3787 # Execute the script. 3788 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data_missing.py') 3789 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 3790 3791 # The R20 keys. 3792 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3793 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3794 3795 # The 'No Rex' model checks. 3796 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 3797 spin4 = return_spin(":4") 3798 spin70 = return_spin(":70") 3799 spin71 = return_spin(":71") 3800 print("\n\nOptimised parameters:\n") 3801 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 3802 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 3803 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 3804 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 3805 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463084515171, 3) 3806 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63220784651911, 3) 3807 self.assertAlmostEqual(spin4.chi2, 26.7356700694891, 3) 3808 self.assertAlmostEqual(spin70.r2[r20_key1], 10.534285641325, 3) 3809 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112794857068, 3) 3810 self.assertAlmostEqual(spin70.chi2, 8973.84809774722, 3) 3811 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83136858890037, 3) 3812 self.assertAlmostEqual(spin71.chi2, 182.60081909193, 3) 3813 3814 # The 'CR72' model checks. 3815 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 3816 spin4 = return_spin(":4") 3817 spin70 = return_spin(":70") 3818 spin71 = return_spin(":71") 3819 print("\n\nOptimised parameters:\n") 3820 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 3821 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 3822 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 3823 print("%-20s %20.15g %20.15g %20.15g" % ("pA", spin4.pA, spin70.pA, spin71.pA)) 3824 print("%-20s %20.15g %20.15g %20.15g" % ("dw", spin4.dw, spin70.dw, spin71.dw)) 3825 print("%-20s %20.15g %20.15g %20.15g" % ("kex", spin4.kex, spin70.kex, spin71.kex)) 3826 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 3827 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463650370664, 2) 3828 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63221675941434, 3) 3829 #self.assertAlmostEqual(spin4.pA, 0.818979078699935, 3) # As dw (and kex) is zero, this parameter is not stable. 3830 self.assertAlmostEqual(spin4.dw, 0.0, 5) 3831 self.assertAlmostEqual(spin4.kex/10000, 0.0, 3) 3832 self.assertAlmostEqual(spin4.chi2/100, 26.7356711142038/100, 3) 3833 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97268077496405, 3) 3834 self.assertAlmostEqual(spin70.r2[r20_key2], 9.41028133407727, 3) 3835 self.assertAlmostEqual(spin70.pA, 0.989856641885939, 3) 3836 self.assertAlmostEqual(spin70.dw, 5.60889911049405, 3) 3837 self.assertAlmostEqual(spin70.kex/10000, 1752.62025618632/10000, 3) 3838 self.assertAlmostEqual(spin70.chi2, 53.8382196964083, 3) 3839 self.assertAlmostEqual(spin71.r2[r20_key1], 4.98123328466942, 3) 3840 self.assertAlmostEqual(spin71.pA, 0.996607425484157, 3) 3841 self.assertAlmostEqual(spin71.dw, 4.34346257383825, 3) 3842 self.assertAlmostEqual(spin71.kex/10000, 1936.73197158804/10000, 3) 3843 self.assertAlmostEqual(spin71.chi2, 5.51703791653689, 3)
3844 3845
3847 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 dispersion model. 3848 3849 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3850 """ 3851 3852 # Base data setup. 3853 self.setup_hansen_cpmg_data(model='CR72') 3854 3855 # Alias the spins. 3856 spin70 = return_spin(":70") 3857 spin71 = return_spin(":71") 3858 3859 # The R20 keys. 3860 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3861 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3862 3863 # Set the initial parameter values. 3864 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 3865 spin70.pA = 0.9 3866 spin70.dw = 6.0 3867 spin70.kex = 1500.0 3868 spin71.r2 = {r20_key1: 5, r20_key2: 9.0} 3869 spin71.pA = 0.9 3870 spin71.dw = 4.0 3871 spin71.kex = 1900.0 3872 3873 # Low precision optimisation. 3874 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 3875 3876 # Printout. 3877 print("\n\nOptimised parameters:\n") 3878 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3879 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3880 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3881 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 3882 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 3883 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3884 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3885 3886 # Checks for residue :70. 3887 self.assertAlmostEqual(spin70.r2[r20_key1], 6.9724581325007, 4) 3888 self.assertAlmostEqual(spin70.r2[r20_key2], 9.40968331038162, 2) 3889 self.assertAlmostEqual(spin70.pA, 0.989856656702431, 4) 3890 self.assertAlmostEqual(spin70.dw, 5.60885879594746, 3) 3891 self.assertAlmostEqual(spin70.kex/1000, 1752.91052702273/1000, 3) 3892 self.assertAlmostEqual(spin70.chi2, 53.8382133597495, 4) 3893 3894 # Checks for residue :71. 3895 self.assertAlmostEqual(spin71.r2[r20_key1], 5.0030740940524, 4) 3896 self.assertAlmostEqual(spin71.pA, 0.985941082507823, 4) 3897 self.assertAlmostEqual(spin71.dw, 2.00640384113696, 4) 3898 self.assertAlmostEqual(spin71.kex/1000, 2480.79614442041/1000, 4) 3899 self.assertAlmostEqual(spin71.chi2, 15.6595388312451, 4) 3900 3901 # Test the conversion to k_AB from kex and pA. 3902 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 3903 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 3904 3905 # Test the conversion to k_BA from kex and pA. 3906 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 3907 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
3908 3909
3911 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 full dispersion model. 3912 3913 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3914 """ 3915 3916 # Base data setup. 3917 self.setup_hansen_cpmg_data(model='CR72 full') 3918 3919 # Alias the spins. 3920 spin70 = return_spin(":70") 3921 spin71 = return_spin(":71") 3922 3923 # The R20 keys. 3924 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3925 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3926 3927 # Set the initial parameter values. 3928 spin70.r2a = {r20_key1: 7.0, r20_key2: 9.0} 3929 spin70.r2b = {r20_key1: 7.0, r20_key2: 9.0} 3930 spin70.pA = 0.9 3931 spin70.dw = 6.0 3932 spin70.kex = 1500.0 3933 spin71.r2a = {r20_key1: 5.0, r20_key2: 9.0} 3934 spin71.r2b = {r20_key1: 5.0, r20_key2: 9.0} 3935 spin71.pA = 0.9 3936 spin71.dw = 4.0 3937 spin71.kex = 1900.0 3938 3939 # Low precision optimisation. 3940 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 3941 3942 # Printout. 3943 print("\n\nOptimised parameters:\n") 3944 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3945 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 3946 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 3947 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 3948 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 3949 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 3950 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 3951 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 3952 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3953 3954 # Checks for residue :70. 3955 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.87485258365614, 4) 3956 self.assertAlmostEqual(spin70.r2b[r20_key1], 1.26075839074614, 4) 3957 self.assertAlmostEqual(spin70.r2a[r20_key2], 8.79580446260797, 4) 3958 self.assertAlmostEqual(spin70.r2b[r20_key2], 51.188411562843, 4) 3959 self.assertAlmostEqual(spin70.pA, 0.989384178573802, 4) 3960 self.assertAlmostEqual(spin70.dw, 5.54738203723682, 4) 3961 self.assertAlmostEqual(spin70.kex/1000, 1831.4566463179/1000, 4) 3962 self.assertAlmostEqual(spin70.chi2, 50.450410782403, 4) 3963 3964 # Checks for residue :71. 3965 self.assertAlmostEqual(spin71.r2a[r20_key1], 5.04185695754972, 4) 3966 self.assertAlmostEqual(spin71.r2b[r20_key1], 1.62857899941921, 4) 3967 self.assertAlmostEqual(spin71.pA, 0.988832866751676, 4) 3968 self.assertAlmostEqual(spin71.dw, 2.24905251856265, 4) 3969 self.assertAlmostEqual(spin71.kex/1000, 2397.64122642946/1000, 4) 3970 self.assertAlmostEqual(spin71.chi2, 15.8586492923672, 4) 3971 3972 # Test the conversion to k_AB from kex and pA. 3973 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 3974 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 3975 3976 # Test the conversion to k_BA from kex and pA. 3977 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 3978 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
3979 3980
3982 """Optimisation of Dr. Flemming Hansen's CPMG data to the IT99 dispersion model. 3983 3984 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3985 """ 3986 3987 # Base data setup. 3988 self.setup_hansen_cpmg_data(model='IT99') 3989 3990 # Alias the spins. 3991 spin70 = return_spin(":70") 3992 spin71 = return_spin(":71") 3993 3994 # The R20 keys. 3995 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3996 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3997 3998 # Set the initial parameter values. 3999 spin70.r2 = {r20_key1: 8.8, r20_key2: 16.6} 4000 spin70.dw = 10.0 4001 spin70.pA = 0.5 4002 spin70.tex = 1000.09 4003 spin71.r2 = {r20_key1: 1.0, r20_key2: 1.0} 4004 spin71.dw = 10.0 4005 spin71.pA = 0.95 4006 spin71.tex = 0.1 4007 4008 # Low precision optimisation. 4009 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-10, grad_tol=None, max_iter=10000, constraints=True, scaling=True, verbosity=1) 4010 4011 # Printout. 4012 print("\n\nOptimised parameters:\n") 4013 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4014 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4015 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4016 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4017 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4018 print("%-20s %20.15g %20.15g" % ("tex", spin70.tex, spin71.tex)) 4019 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4020 4021 # Checks for residue :70. 4022 self.assertAlmostEqual(spin70.r2[r20_key1], 7.24471197811838, 4) 4023 self.assertAlmostEqual(spin70.r2[r20_key2], 10.0571040704729, 4) 4024 self.assertAlmostEqual(spin70.dw, 5.2116923222744, 4) 4025 self.assertAlmostEqual(spin70.pA, 0.990253627907212, 4) 4026 self.assertAlmostEqual(spin70.tex*1000, 0.000638394793480444*1000, 4) 4027 self.assertAlmostEqual(spin70.chi2, 93.5135798618747, 4) 4028 4029 # Checks for residue :71. 4030 self.assertAlmostEqual(spin71.r2[r20_key1], 5.05971235970214, 4) 4031 self.assertAlmostEqual(spin71.r2[r20_key2], 6.96641194493447, 4) 4032 self.assertAlmostEqual(spin71.dw, 0.435389946897141, 4) 4033 self.assertAlmostEqual(spin71.pA, 0.500000000213519, 3) 4034 self.assertAlmostEqual(spin71.tex*1000, 0.000372436400585538*1000, 4) 4035 self.assertAlmostEqual(spin71.chi2, 23.7895798801404, 4)
4036 4037
4039 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4040 4041 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4042 """ 4043 4044 # Base data setup. 4045 self.setup_hansen_cpmg_data(model='LM63') 4046 4047 # Alias the spins. 4048 spin70 = return_spin(":70") 4049 spin71 = return_spin(":71") 4050 4051 # The R20 keys. 4052 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4053 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4054 4055 # Set the initial parameter values. 4056 spin70.r2 = {r20_key1: 7.0, r20_key2: 7.0} 4057 spin70.phi_ex = 0.3 4058 spin70.kex = 5000.0 4059 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4060 spin71.phi_ex = 0.1 4061 spin71.kex = 2500.0 4062 4063 # Low precision optimisation. 4064 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4065 4066 # Printout. 4067 print("\n\nOptimised parameters:\n") 4068 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4069 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4070 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4071 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4072 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4073 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4074 4075 # Checks for residue :70. 4076 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74362294539099) 4077 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406797067481, 6) 4078 self.assertAlmostEqual(spin70.phi_ex, 0.312733013751449) 4079 self.assertAlmostEqual(spin70.kex/1000, 4723.09897146338/1000, 6) 4080 self.assertAlmostEqual(spin70.chi2, 363.534044873483) 4081 4082 # Checks for residue :71. 4083 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00776657729728, 5) 4084 self.assertAlmostEqual(spin71.phi_ex, 0.0553787825650613, 5) 4085 self.assertAlmostEqual(spin71.kex/1000, 2781.72292994154/1000, 5) 4086 self.assertAlmostEqual(spin71.chi2, 17.0776399916287, 5)
4087 4088
4090 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4091 4092 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4093 """ 4094 4095 # Base data setup. 4096 self.setup_hansen_cpmg_data(model='LM63 3-site') 4097 4098 # Alias the spins. 4099 spin70 = return_spin(":70") 4100 spin71 = return_spin(":71") 4101 4102 # The R20 keys. 4103 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4104 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4105 4106 ## Set the initial parameter values. 4107 spin70.r2 = {r20_key1: 7.570370921220954, r20_key2: 8.694446951909107} 4108 spin70.phi_ex_B = 0.14872003058250227 4109 spin70.phi_ex_C = 0.1319419923472704 4110 spin70.kB = 4103.672910444741 4111 spin70.kC = 7029.001690726248 4112 spin71.r2 = {r20_key1: 5.1347793381636, r20_key2: 7.156573986051575} 4113 spin71.phi_ex_B = 0.04013553485505605 4114 spin71.phi_ex_C = 0.020050748406928887 4115 spin71.kB = 4045.3007136121364 4116 spin71.kC = 3586.38798270774 4117 4118 #self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 4119 #self.interpreter.minimise.grid_search(lower=None, upper=None, inc=41, constraints=True, verbosity=1) 4120 4121 # Low precision optimisation. 4122 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4123 4124 # Printout. 4125 print("\n\nOptimised parameters:\n") 4126 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4127 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4128 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4129 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin70.phi_ex_B, spin71.phi_ex_B)) 4130 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin70.phi_ex_C, spin71.phi_ex_C)) 4131 print("%-20s %20.15g %20.15g" % ("kB", spin70.kB, spin71.kB)) 4132 print("%-20s %20.15g %20.15g" % ("kC", spin70.kC, spin71.kC)) 4133 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4134 4135 # Checks for residue :70. 4136 self.assertAlmostEqual(spin70.r2[r20_key1], 6.7436230253685, 5) 4137 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406813008828, 6) 4138 self.assertAlmostEqual(spin70.phi_ex_B, 0.206304023079778, 5) 4139 self.assertAlmostEqual(spin70.phi_ex_C, 0.106428983339627, 5) 4140 self.assertAlmostEqual(spin70.kB/1000, 4723.09897652589/1000, 6) 4141 self.assertAlmostEqual(spin70.kC/1000, 4723.09876196409/1000, 6) 4142 self.assertAlmostEqual(spin70.chi2, 363.534044873483, 5) 4143 4144 # Checks for residue :71. 4145 self.assertAlmostEqual(spin71.r2[r20_key1], 4.96612095596752, 5) 4146 self.assertAlmostEqual(spin71.phi_ex_B, 0.00398262266512895, 5) 4147 self.assertAlmostEqual(spin71.phi_ex_C, 0.0555791581291262, 5) 4148 self.assertAlmostEqual(spin71.kB/1000, 1323.33195689832/1000, 5) 4149 self.assertAlmostEqual(spin71.kC/1000, 3149.58971568059/1000, 5) 4150 self.assertAlmostEqual(spin71.chi2, 16.2620934464368)
4151 4152
4154 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D' dispersion model. 4155 4156 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4157 """ 4158 4159 # Base data setup. 4160 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D') 4161 4162 # Alias the spins. 4163 spin70 = return_spin(":70") 4164 spin71 = return_spin(":71") 4165 4166 # The R20 keys. 4167 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4168 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4169 4170 # Set the initial parameter values. 4171 spin70.r2 = {r20_key1: 6.994165925, r20_key2: 9.428129427} 4172 spin70.pA = 0.9897754407 4173 spin70.dw = 5.642418428 4174 spin70.kex = 1743.666375 4175 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4176 spin71.pA = 0.9968032899 4177 spin71.dw = 4.577891393 4178 spin71.kex = 1830.044597 4179 4180 # Low precision optimisation. 4181 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4182 4183 # Printout. 4184 print("\n\nOptimised parameters:\n") 4185 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4186 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4187 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4188 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4189 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4190 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4191 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4192 4193 # Checks for residue :70. 4194 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95797760459016, 4) 4195 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39628959312699, 4) 4196 self.assertAlmostEqual(spin70.pA, 0.989700985380975, 4) 4197 self.assertAlmostEqual(spin70.dw, 5.6733714171086, 4) 4198 self.assertAlmostEqual(spin70.kex/1000, 1713.63101361545/1000, 4) 4199 self.assertAlmostEqual(spin70.chi2, 52.5106928523775, 4) 4200 4201 # Checks for residue :71. 4202 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99893565849977, 4) 4203 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89825625944034, 4) 4204 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 4) 4205 self.assertAlmostEqual(spin71.dw, 2.09292495350993, 4) 4206 self.assertAlmostEqual(spin71.kex/1000, 2438.04423541463/1000, 4) 4207 self.assertAlmostEqual(spin71.chi2, 15.164490242352, 4) 4208 4209 # Test the conversion to k_AB from kex and pA. 4210 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4211 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4212 4213 # Test the conversion to k_BA from kex and pA. 4214 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4215 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4216 4217
4219 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D full' dispersion model. 4220 4221 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4222 """ 4223 4224 # Base data setup. 4225 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D full') 4226 4227 # Alias the spins. 4228 spin70 = return_spin(":70") 4229 spin71 = return_spin(":71") 4230 4231 # The R20 keys. 4232 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4233 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4234 4235 # Set the initial parameter values. 4236 spin70.r2a = {r20_key1: 6.644753428, r20_key2: 7.891776687} 4237 spin70.r2b = {r20_key1: 7.163478485, r20_key2: 138.5170395} 4238 spin70.pA = 0.9884781357 4239 spin70.dw = 5.456507396 4240 spin70.kex = 1906.521189 4241 spin71.r2a = {r20_key1: 4.99893524108981, r20_key2: 100.0} 4242 spin71.r2b = {r20_key1: 8.27456243639973, r20_key2: 100.0} 4243 spin71.pA = 0.986709616684097 4244 spin71.dw = 2.09245158280905 4245 spin71.kex = 2438.2766211401 4246 4247 # Low precision optimisation. 4248 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4249 4250 # Printout. 4251 print("\n\nOptimised parameters:\n") 4252 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4253 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4254 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4255 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4256 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4257 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4258 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4259 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4260 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4261 4262 # Checks for residue :70. 4263 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.61176004043484, 4) 4264 self.assertAlmostEqual(spin70.r2b[r20_key1], 7.4869316381241, 4) 4265 self.assertAlmostEqual(spin70.r2a[r20_key2], 7.78200386067591, 4) 4266 self.assertAlmostEqual(spin70.r2b[r20_key2], 141.703593742468, 4) 4267 self.assertAlmostEqual(spin70.pA, 0.988404987055969, 4) 4268 self.assertAlmostEqual(spin70.dw, 5.4497360203213, 4) 4269 self.assertAlmostEqual(spin70.kex/1000, 1934.09304607082/1000, 4) 4270 self.assertAlmostEqual(spin70.chi2, 44.6793752187925, 4) 4271 4272 # Checks for residue :71. 4273 self.assertAlmostEqual(spin71.r2a[r20_key1], 4.6013095731966, 4) 4274 self.assertAlmostEqual(spin71.r2b[r20_key1], 13.3245678276332, 4) 4275 self.assertAlmostEqual(spin71.r2a[r20_key2], 2.08243621257779, 4) 4276 self.assertAlmostEqual(spin71.r2b[r20_key2], 153.355765094575, 4) 4277 self.assertAlmostEqual(spin71.pA, 0.9665748685124, 4) 4278 self.assertAlmostEqual(spin71.dw, 1.41898001408953, 4) 4279 self.assertAlmostEqual(spin71.kex/1000, 2580.65795560688/1000, 4) 4280 self.assertAlmostEqual(spin71.chi2, 13.4937006732165, 4) 4281 4282 # Test the conversion to k_AB from kex and pA. 4283 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4284 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4285 4286 # Test the conversion to k_BA from kex and pA. 4287 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4288 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4289 4290
4292 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site expanded' dispersion model. 4293 4294 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4295 """ 4296 4297 # Base data setup. 4298 self.setup_hansen_cpmg_data(model='NS CPMG 2-site expanded') 4299 4300 # Alias the spins. 4301 spin70 = return_spin(":70") 4302 spin71 = return_spin(":71") 4303 4304 # The R20 keys. 4305 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4306 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4307 4308 # Set the initial parameter values. 4309 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4310 spin70.pA = 0.9 4311 spin70.dw = 6.0 4312 spin70.kex = 1500.0 4313 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4314 spin71.pA = 0.9 4315 spin71.dw = 4.0 4316 spin71.kex = 1900.0 4317 4318 # Low precision optimisation. 4319 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4320 4321 # Printout. 4322 print("\n\nOptimised parameters:\n") 4323 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4324 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4325 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4326 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4327 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4328 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4329 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4330 4331 # Checks for residue :70. 4332 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95813330991529, 4) 4333 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39663480561524, 4) 4334 self.assertAlmostEqual(spin70.pA, 0.989700843879574, 4) 4335 self.assertAlmostEqual(spin70.dw, 5.67315878825691, 4) 4336 self.assertAlmostEqual(spin70.kex/1000, 1713.56110716632/1000, 4) 4337 self.assertAlmostEqual(spin70.chi2, 52.5106879242812, 4) 4338 4339 # Checks for residue :71. 4340 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99881666793312, 4) 4341 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89817482453042, 4) 4342 self.assertAlmostEqual(spin71.pA, 0.986712911453639, 4) 4343 self.assertAlmostEqual(spin71.dw, 2.09273069372236, 4) 4344 self.assertAlmostEqual(spin71.kex/1000, 2438.20525930405/1000, 4) 4345 self.assertAlmostEqual(spin71.chi2, 15.1644913030633, 4) 4346 4347 # Test the conversion to k_AB from kex and pA. 4348 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4349 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4350 4351 # Test the conversion to k_BA from kex and pA. 4352 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4353 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4354 4355
4357 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star' dispersion model. 4358 4359 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4360 """ 4361 4362 # Base data setup. 4363 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star') 4364 4365 # Alias the spins. 4366 spin70 = return_spin(":70") 4367 spin71 = return_spin(":71") 4368 4369 # The R20 keys. 4370 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4371 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4372 4373 # Set the initial parameter values. 4374 spin70.r2 = {r20_key1: 6.996327746, r20_key2: 9.452051268} 4375 spin70.pA = 0.9897519798 4376 spin70.dw = 5.644862195 4377 spin70.kex = 1723.820567 4378 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4379 spin71.pA = 0.9968032899 4380 spin71.dw = 4.577891393 4381 spin71.kex = 1830.044597 4382 4383 # Low precision optimisation. 4384 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4385 4386 # Printout. 4387 print("\n\nOptimised parameters:\n") 4388 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4389 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4390 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4391 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4392 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4393 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4394 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4395 4396 # Checks for residue :70. 4397 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95543947938561, 1) 4398 self.assertAlmostEqual(spin70.r2[r20_key2], 9.38991914134929, 1) 4399 self.assertAlmostEqual(spin70.pA, 0.989702750971153, 3) 4400 self.assertAlmostEqual(spin70.dw, 5.67527122494516, 1) 4401 self.assertAlmostEqual(spin70.kex/1000, 1715.72032391817/1000, 1) 4402 self.assertAlmostEqual(spin70.chi2, 52.5011991483842, 1) 4403 4404 # Checks for residue :71. 4405 self.assertAlmostEqual(spin71.r2[r20_key1], 4.992594256544, 1) 4406 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 2) 4407 self.assertAlmostEqual(spin71.dw/100, 2.09292495350993/100, 2) 4408 self.assertAlmostEqual(spin71.kex/100000, 2438.04423541463/100000, 2) 4409 self.assertAlmostEqual(spin71.chi2/100, 15.1644902423334/100, 1) 4410 4411 # Test the conversion to k_AB from kex and pA. 4412 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4413 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4414 4415 # Test the conversion to k_BA from kex and pA. 4416 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4417 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4418 4419
4421 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star full' dispersion model. 4422 4423 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4424 """ 4425 4426 # Base data setup. 4427 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star full') 4428 4429 # Alias the spins. 4430 spin70 = return_spin(":70") 4431 spin71 = return_spin(":71") 4432 4433 # The R20 keys. 4434 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4435 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4436 4437 # Set the initial parameter values. 4438 spin70.r2a = {r20_key1: 6.44836878645126, r20_key2: 7.00382877393494} 4439 spin70.r2b = {r20_key1: 12.2083127421994, r20_key2: 199.862962628402} 4440 spin70.pA = 0.987648082613451 4441 spin70.dw = 5.30679853807572 4442 spin70.kex = 2033.25380420666 4443 spin71.r2a = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4444 spin71.r2b = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4445 spin71.pA = 0.992258541625787 4446 spin71.dw = 2.75140650899058 4447 spin71.kex = 2106.60885247431 4448 4449 # Low precision optimisation. 4450 self.interpreter.minimise.calculate() 4451 4452 # Checks for residue :70. 4453 self.assertAlmostEqual(spin70.chi2/10, 45.773987568491123/10, 2) 4454 self.assertAlmostEqual(spin71.chi2/10, 17.329385665659192/10, 2)
4455 4456
4457 - def test_hansen_cpmgfit_input(self):
4458 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CPMGFit. 4459 4460 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4461 """ 4462 4463 # Load the R2eff results file. 4464 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 4465 self.interpreter.results.read(file_name) 4466 self.interpreter.deselect.spin(':4') 4467 4468 # Set up the model. 4469 self.interpreter.relax_disp.select_model('LM63') 4470 4471 # Generate the input files. 4472 self.interpreter.relax_disp.cpmgfit_input(force=True, dir=ds.tmpdir) 4473 4474 # What the files should contain. 4475 batch_file = ['#! /bin/sh\n', '\n', 'cpmgfit -grid -xmgr -f spin_70_N.in | tee spin_70_N.out\n', 'cpmgfit -grid -xmgr -f spin_71_N.in | tee spin_71_N.out\n'] 4476 spin1 = [ 4477 "title :70@N\n", 4478 "fields 2 11.7432964915 18.7892743865\n", 4479 "function CPMG\n", 4480 "R2 1 10 20\n", 4481 "Rex 0 100.0 100\n", 4482 "Tau 0 10.0 100\n", 4483 "xmgr\n", 4484 "@ xaxis label \"1/tcp (1/ms)\"\n", 4485 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4486 "@ xaxis ticklabel format decimal\n", 4487 "@ yaxis ticklabel format decimal\n", 4488 "@ xaxis ticklabel char size 0.8\n", 4489 "@ yaxis ticklabel char size 0.8\n", 4490 "@ world xmin 0.0\n", 4491 "data\n", 4492 "0.133333 16.045541 0.310925 11.743296 \n", 4493 "0.266667 14.877925 0.303217 11.743296 \n", 4494 "0.400000 14.357820 0.299894 11.743296 \n", 4495 "0.533333 12.664495 0.289532 11.743296 \n", 4496 "0.666667 12.363205 0.287760 11.743296 \n", 4497 "0.800000 11.092532 0.280514 11.743296 \n", 4498 "0.933333 10.566090 0.277619 11.743296 \n", 4499 "1.066667 9.805807 0.273544 11.743296 \n", 4500 "1.200000 9.564301 0.272276 11.743296 \n", 4501 "1.333333 9.015634 0.269442 11.743296 \n", 4502 "1.466667 8.607765 0.267375 11.743296 \n", 4503 "1.600000 8.279997 0.265740 11.743296 \n", 4504 "1.733333 8.474536 0.266708 11.743296 \n", 4505 "1.866667 8.158973 0.265141 11.743296 \n", 4506 "2.000000 7.988631 0.264304 11.743296 \n", 4507 "0.133333 22.224914 0.166231 18.789274 \n", 4508 "0.266667 21.230874 0.162377 18.789274 \n", 4509 "0.400000 20.603704 0.160017 18.789274 \n", 4510 "0.533333 20.327797 0.158996 18.789274 \n", 4511 "0.666667 18.855377 0.153719 18.789274 \n", 4512 "0.800000 18.537531 0.152617 18.789274 \n", 4513 "0.933333 17.508069 0.149138 18.789274 \n", 4514 "1.066667 16.035604 0.144391 18.789274 \n", 4515 "1.200000 15.168192 0.141717 18.789274 \n", 4516 "1.333333 14.431802 0.139516 18.789274 \n", 4517 "1.466667 14.034137 0.138354 18.789274 \n", 4518 "1.600000 12.920148 0.135192 18.789274 \n", 4519 "1.733333 12.653673 0.134456 18.789274 \n", 4520 "1.866667 12.610864 0.134338 18.789274 \n", 4521 "2.000000 11.969303 0.132601 18.789274 \n" 4522 ] 4523 spin2 = [ 4524 "title :71@N\n", 4525 "fields 2 11.7432964915 18.7892743865\n", 4526 "function CPMG\n", 4527 "R2 1 10 20\n", 4528 "Rex 0 100.0 100\n", 4529 "Tau 0 10.0 100\n", 4530 "xmgr\n", 4531 "@ xaxis label \"1/tcp (1/ms)\"\n", 4532 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4533 "@ xaxis ticklabel format decimal\n", 4534 "@ yaxis ticklabel format decimal\n", 4535 "@ xaxis ticklabel char size 0.8\n", 4536 "@ yaxis ticklabel char size 0.8\n", 4537 "@ world xmin 0.0\n", 4538 "data\n", 4539 "0.133333 7.044342 0.170035 11.743296 \n", 4540 "0.266667 6.781033 0.169228 11.743296 \n", 4541 "0.400000 6.467623 0.168279 11.743296 \n", 4542 "0.533333 6.333340 0.167876 11.743296 \n", 4543 "0.666667 6.323238 0.167846 11.743296 \n", 4544 "0.800000 6.005245 0.166902 11.743296 \n", 4545 "0.933333 5.767052 0.166203 11.743296 \n", 4546 "1.066667 5.476968 0.165361 11.743296 \n", 4547 "1.200000 5.469949 0.165341 11.743296 \n", 4548 "1.333333 5.295113 0.164838 11.743296 \n", 4549 "1.466667 5.435648 0.165242 11.743296 \n", 4550 "1.600000 5.410400 0.165169 11.743296 \n", 4551 "1.733333 5.437554 0.165247 11.743296 \n", 4552 "1.866667 5.176844 0.164501 11.743296 \n", 4553 "2.000000 5.227232 0.164644 11.743296 \n", 4554 "0.133333 11.530903 0.081928 18.789274 \n", 4555 "0.266667 10.983094 0.081041 18.789274 \n", 4556 "0.400000 10.512403 0.080294 18.789274 \n", 4557 "0.533333 9.984805 0.079473 18.789274 \n", 4558 "0.666667 9.573163 0.078845 18.789274 \n", 4559 "0.800000 9.178810 0.078253 18.789274 \n", 4560 "0.933333 8.935719 0.077893 18.789274 \n", 4561 "1.066667 8.610147 0.077416 18.789274 \n", 4562 "1.200000 8.353778 0.077045 18.789274 \n", 4563 "1.333333 8.173729 0.076787 18.789274 \n", 4564 "1.466667 8.091607 0.076670 18.789274 \n", 4565 "1.600000 7.706420 0.076126 18.789274 \n", 4566 "1.733333 7.709125 0.076129 18.789274 \n", 4567 "1.866667 7.610856 0.075992 18.789274 \n", 4568 "2.000000 7.552584 0.075911 18.789274 \n", 4569 ] 4570 4571 # Check the batch file. 4572 print("\nChecking the batch file.") 4573 file = open("%s%sbatch_run.sh" % (ds.tmpdir, sep)) 4574 lines = file.readlines() 4575 file.close() 4576 for i in range(len(lines)): 4577 self.assertEqual(batch_file[i], lines[i]) 4578 4579 # Check spin :70@N. 4580 print("\nChecking the spin :70@N input file.") 4581 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_70_N')) 4582 lines = file.readlines() 4583 file.close() 4584 for i in range(len(spin1)): 4585 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 4586 for i in range(len(lines)): 4587 self.assertEqual(spin1[i], lines[i]) 4588 4589 # Check spin :71@N. 4590 print("\nChecking the spin :71@N input file.") 4591 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_71_N')) 4592 lines = file.readlines() 4593 file.close() 4594 for i in range(len(lines)): 4595 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 4596 for i in range(len(spin2)): 4597 self.assertEqual(spin2[i], lines[i])
4598 4599
4601 """Optimisation of the Korzhnev et al., 2005 15N DQ CPMG data using the 'NS MMQ 2-site' model. 4602 4603 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 4604 4605 Here only the 15N DQ data will be optimised. The values found by cpmg_fit using just this data are: 4606 4607 - r2 = {'500': 9.487269007171426, '600': 11.718267257562591, '800': 13.624551743116887}, 4608 - pA = 0.965402506690231, 4609 - dw = 0.805197170133360, 4610 - dwH = -0.595536627771890, 4611 - kex = 569.003663067619868, 4612 - chi2 = 9.297671357952812. 4613 """ 4614 4615 # Base data setup. 4616 self.setup_korzhnev_2005_data(data_list=['DQ']) 4617 4618 # Alias the spin. 4619 spin = return_spin(":9@N") 4620 4621 # The R20 keys. 4622 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 4623 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 4624 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 4625 4626 # Set the initial parameter values. 4627 spin.r2 = {r20_key1: 9.48527908326952, r20_key2: 11.7135951595536, r20_key3: 13.6153887849344} 4628 spin.pA = 0.965638501551899 4629 spin.dw = 2.8537583461577 4630 spin.dwH = -0.387633062766635 4631 spin.kex = 573.704033851592 4632 4633 # Low precision optimisation. 4634 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 4635 4636 # Monte Carlo simulations. 4637 self.interpreter.monte_carlo.setup(number=2) 4638 self.interpreter.monte_carlo.create_data(method='back_calc') 4639 self.interpreter.monte_carlo.initial_values() 4640 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 4641 self.interpreter.monte_carlo.error_analysis() 4642 4643 # Plot the dispersion curves. 4644 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 4645 4646 # Save the results. 4647 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 4648 4649 # Printout. 4650 print("\n\nOptimised parameters:\n") 4651 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 4652 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 4653 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 4654 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 4655 print("%-20s %20.15g" % ("pA", spin.pA)) 4656 print("%-20s %20.15g" % ("dw", spin.dw)) 4657 print("%-20s %20.15g" % ("dwH", spin.dwH)) 4658 print("%-20s %20.15g" % ("kex", spin.kex)) 4659 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 4660 4661 # Checks for residue :9. 4662 self.assertAlmostEqual(spin.r2[r20_key1], 9.48527908326952, 2) 4663 self.assertAlmostEqual(spin.r2[r20_key2], 11.7135951595536, 2) 4664 self.assertAlmostEqual(spin.r2[r20_key3], 13.6153887849344, 2) 4665 self.assertAlmostEqual(spin.pA, 0.965638501551899, 4) 4666 self.assertAlmostEqual(spin.dw, 2.8537583461577, 1) 4667 self.assertAlmostEqual(spin.dwH, -0.387633062766635, 2) 4668 self.assertAlmostEqual(spin.kex/1000, 573.704033851592/1000, 3) 4669 self.assertAlmostEqual(spin.chi2, 9.29563496654824, 2)
4670 4671
4673 """Optimisation of the Korzhnev et al., 2005 15N MQ CPMG data using the 'NS MMQ 2-site' model. 4674 4675 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 4676 4677 Here only the 15N MQ data will be optimised. The values found by cpmg_fit using just this data are: 4678 4679 - r2 = {'500': 5.993083514798655, '600': 6.622184438384841, '800': 8.640765919352019}, 4680 - pA = 0.930027999814003, 4681 - dw = 4.338620619954370, 4682 - dwH = -0.274250775560818, 4683 - kex = 344.613362916544475, 4684 - chi2 = 10.367733168217050. 4685 """ 4686 4687 # Base data setup. 4688 self.setup_korzhnev_2005_data(data_list=['MQ']) 4689 4690 # Alias the spin. 4691 spin = return_spin(":9@N") 4692 4693 # The R20 keys. 4694 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 4695 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 4696 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 4697 4698 # Set the initial parameter values. 4699 spin.r2 = {r20_key1: 6.02016436619016, r20_key2: 6.65421500772308, r20_key3: 8.6729591487622} 4700 spin.pA = 0.930083249288083 4701 spin.dw = 4.33890689462363 4702 spin.dwH = -0.274316585638047 4703 spin.kex = 344.329651956132 4704 4705 # Low precision optimisation. 4706 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 4707 4708 # Monte Carlo simulations. 4709 self.interpreter.monte_carlo.setup(number=2) 4710 self.interpreter.monte_carlo.create_data(method='back_calc') 4711 self.interpreter.monte_carlo.initial_values() 4712 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 4713 self.interpreter.monte_carlo.error_analysis() 4714 4715 # Plot the dispersion curves. 4716 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 4717 4718 # Save the results. 4719 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 4720 4721 # Printout. 4722 print("\n\nOptimised parameters:\n") 4723 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 4724 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 4725 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 4726 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 4727 print("%-20s %20.15g" % ("pA", spin.pA)) 4728 print("%-20s %20.15g" % ("dw", spin.dw)) 4729 print("%-20s %20.15g" % ("dwH", spin.dwH)) 4730 print("%-20s %20.15g" % ("kex", spin.kex)) 4731 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 4732 4733 # Checks for residue :9. 4734 self.assertAlmostEqual(spin.r2[r20_key1], 6.02016436619016, 1) 4735 self.assertAlmostEqual(spin.r2[r20_key2], 6.65421500772308, 1) 4736 self.assertAlmostEqual(spin.r2[r20_key3], 8.6729591487622, 1) 4737 self.assertAlmostEqual(spin.pA, 0.930083249288083, 3) 4738 self.assertAlmostEqual(spin.dw, 4.33890689462363, 2) 4739 self.assertAlmostEqual(spin.dwH, -0.274316585638047, 3) 4740 self.assertAlmostEqual(spin.kex/1000, 344.329651956132/1000, 3) 4741 self.assertAlmostEqual(spin.chi2, 10.3654315659173, 2)
4742 4743
4745 """Optimisation of the Korzhnev et al., 2005 15N SQ CPMG data using the 'NS MMQ 2-site' model. 4746 4747 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 4748 4749 Here only the 15N SQ data will be optimised. The values found by cpmg_fit using just this data are: 4750 4751 - r2 = {'500': 8.335037972570017, '600': 8.761366016417508, '800': 10.225001019091822}, 4752 - pA = 0.950003458294991, 4753 - dw = 4.358402855315123, 4754 - kex = 429.906473361926999, 4755 - chi2 = 17.393331915567252. 4756 """ 4757 4758 # Base data setup. 4759 self.setup_korzhnev_2005_data(data_list=['SQ']) 4760 4761 # Alias the spin. 4762 spin = return_spin(":9@N") 4763 4764 # The R20 keys. 4765 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4766 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 4767 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4768 4769 # Set the initial parameter values. 4770 spin.r2 = {r20_key1: 8.334232330326190, r20_key2: 8.756773997879968, r20_key3: 10.219320492033058} 4771 spin.pA = 0.950310172115387 4772 spin.dw = 4.356737157889636 4773 spin.kex = 433.176323890829849 4774 4775 # Low precision optimisation. 4776 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 4777 4778 # Monte Carlo simulations. 4779 self.interpreter.monte_carlo.setup(number=2) 4780 self.interpreter.monte_carlo.create_data(method='back_calc') 4781 self.interpreter.monte_carlo.initial_values() 4782 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 4783 self.interpreter.monte_carlo.error_analysis() 4784 4785 # Plot the dispersion curves. 4786 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 4787 4788 # Save the results. 4789 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 4790 4791 # Printout. 4792 print("\n\nOptimised parameters:\n") 4793 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 4794 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 4795 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 4796 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 4797 print("%-20s %20.15g" % ("pA", spin.pA)) 4798 print("%-20s %20.15g" % ("dw", spin.dw)) 4799 print("%-20s %20.15g" % ("kex", spin.kex)) 4800 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 4801 4802 # Checks for residue :9. 4803 self.assertAlmostEqual(spin.r2[r20_key1], 8.334232330326190, 2) 4804 self.assertAlmostEqual(spin.r2[r20_key2], 8.756773997879968, 2) 4805 self.assertAlmostEqual(spin.r2[r20_key3], 10.219320492033058, 1) 4806 self.assertAlmostEqual(spin.pA, 0.950310172115387, 3) 4807 self.assertAlmostEqual(spin.dw, 4.356737157889636, 2) 4808 self.assertAlmostEqual(spin.kex/1000, 433.176323890829849/1000, 2) 4809 self.assertAlmostEqual(spin.chi2, 17.37460582872912, 1)
4810 4811
4813 """Optimisation of the Korzhnev et al., 2005 15N ZQ CPMG data using the 'NS MMQ 2-site' model. 4814 4815 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 4816 4817 Here only the 15N ZQ data will be optimised. The values found by cpmg_fit using just this data are: 4818 4819 - r2 = {'500': 5.909812628572937, '600': 6.663690132557320, '800': 6.787171647689906}, 4820 - pA = 0.942452612380140, 4821 - dw = 0.858972784230892, 4822 - dwH = 0.087155962730608, 4823 - kex = 373.219151384798920, 4824 - chi2 = 23.863208106025152. 4825 """ 4826 4827 # Base data setup. 4828 self.setup_korzhnev_2005_data(data_list=['ZQ']) 4829 4830 # Alias the spin. 4831 spin = return_spin(":9@N") 4832 4833 # The R20 keys. 4834 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 4835 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 4836 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 4837 4838 # Set the initial parameter values. 4839 spin.r2 = {r20_key1: 5.91033272691614, r20_key2: 6.66368695342258, r20_key3: 6.78922219135537} 4840 spin.pA = 0.942457332074014 4841 spin.dw = 0.850592422908884 4842 spin.dwH = 0.0881272284455416 4843 spin.kex = 372.745483351305 4844 4845 # Low precision optimisation. 4846 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 4847 4848 # Monte Carlo simulations. 4849 self.interpreter.monte_carlo.setup(number=2) 4850 self.interpreter.monte_carlo.create_data(method='back_calc') 4851 self.interpreter.monte_carlo.initial_values() 4852 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 4853 self.interpreter.monte_carlo.error_analysis() 4854 4855 # Plot the dispersion curves. 4856 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 4857 4858 # Save the results. 4859 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 4860 4861 # Printout. 4862 print("\n\nOptimised parameters:\n") 4863 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 4864 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 4865 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 4866 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 4867 print("%-20s %20.15g" % ("pA", spin.pA)) 4868 print("%-20s %20.15g" % ("dw", spin.dw)) 4869 print("%-20s %20.15g" % ("dwH", spin.dwH)) 4870 print("%-20s %20.15g" % ("kex", spin.kex)) 4871 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 4872 4873 # Checks for residue :9. 4874 self.assertAlmostEqual(spin.r2[r20_key1], 5.91033272691614, 2) 4875 self.assertAlmostEqual(spin.r2[r20_key2], 6.66368695342258, 2) 4876 self.assertAlmostEqual(spin.r2[r20_key3], 6.78922219135537, 2) 4877 self.assertAlmostEqual(spin.pA, 0.942457332074014, 4) 4878 self.assertAlmostEqual(spin.dw, 0.850592422908884, 1) 4879 self.assertAlmostEqual(spin.dwH, 0.0881272284455416, 2) 4880 self.assertAlmostEqual(spin.kex/1000, 372.745483351305/1000, 3) 4881 self.assertAlmostEqual(spin.chi2, 23.8464637019392, 1)
4882 4883
4885 """Optimisation of the Korzhnev et al., 2005 1H MQ CPMG data using the 'NS MMQ 2-site' model. 4886 4887 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 4888 4889 Here only the 1H MQ data will be optimised. The values found by cpmg_fit using just this data are: 4890 4891 - r2 = {'500': -0.000016676911302, '600': 0.036594127620440, '800': 2.131014839635728}, 4892 - pA = 0.936911090448340, 4893 - dw = 4.325314846914845, 4894 - dwH = -0.213870168665628, 4895 - kex = 487.361914835074117, 4896 - chi2 = 14.870371897291138. 4897 """ 4898 4899 # Base data setup. 4900 self.setup_korzhnev_2005_data(data_list=['1H MQ']) 4901 4902 # Alias the spin. 4903 spin = return_spin(":9@N") 4904 4905 # The R20 keys. 4906 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 4907 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 4908 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 4909 4910 # Set the initial parameter values. 4911 spin.r2 = {r20_key1: 0.000022585022901, r20_key2: 0.039223196112941, r20_key3: 2.136576686700357} 4912 spin.pA = 0.936884348941701 4913 spin.dw = 4.326454531583964 4914 spin.dwH = -0.214026093221782 4915 spin.kex = 487.043592705469223 4916 4917 # Low precision optimisation. 4918 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=100) 4919 4920 # Monte Carlo simulations. 4921 self.interpreter.monte_carlo.setup(number=2) 4922 self.interpreter.monte_carlo.create_data(method='back_calc') 4923 self.interpreter.monte_carlo.initial_values() 4924 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 4925 self.interpreter.monte_carlo.error_analysis() 4926 4927 # Plot the dispersion curves. 4928 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 4929 4930 # Save the results. 4931 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 4932 4933 # Printout. 4934 print("\n\nOptimised parameters:\n") 4935 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 4936 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 4937 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 4938 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 4939 print("%-20s %20.15g" % ("pA", spin.pA)) 4940 print("%-20s %20.15g" % ("dw", spin.dw)) 4941 print("%-20s %20.15g" % ("dwH", spin.dwH)) 4942 print("%-20s %20.15g" % ("kex", spin.kex)) 4943 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 4944 4945 # Checks for residue :9. 4946 self.assertAlmostEqual(spin.r2[r20_key1], 0.000023714274046, 4) 4947 self.assertAlmostEqual(spin.r2[r20_key2], 0.039223196112941, 2) 4948 self.assertAlmostEqual(spin.r2[r20_key3], 2.13657668670036, 2) 4949 self.assertAlmostEqual(spin.pA, 0.936884348941701, 4) 4950 self.assertAlmostEqual(spin.dw, 4.32645453158396, 2) 4951 self.assertAlmostEqual(spin.dwH, -0.214026093221782, 2) 4952 self.assertAlmostEqual(spin.kex/1000, 487.043592705469/1000, 4) 4953 self.assertAlmostEqual(spin.chi2, 14.8642315375301, 2)
4954 4955
4957 """Optimisation of the Korzhnev et al., 2005 1H SQ CPMG data using the 'NS MMQ 2-site' model. 4958 4959 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 4960 4961 Here only the 1H SQ data will be optimised. The values found by cpmg_fit using just this data are: 4962 4963 - r2 = {'500': 6.691697587650816, '600': 6.998915158708793, '800': 5.519267837559072}, 4964 - pA = 0.946949480545876, 4965 - dwH = -0.265279672133308, 4966 - kex = 406.548178869750700, 4967 - chi2 = 50.400680290545026. 4968 """ 4969 4970 # Base data setup. 4971 self.setup_korzhnev_2005_data(data_list=['1H SQ']) 4972 4973 # Alias the spin. 4974 spin = return_spin(":9@N") 4975 4976 # The R20 keys. 4977 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 4978 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 4979 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 4980 4981 # Set the initial parameter values. 4982 spin.r2 = {r20_key1: 6.69107911078939, r20_key2: 6.99888898689085, r20_key3: 5.52012880268077} 4983 spin.pA = 0.946990967372467 4984 spin.dwH = -0.265308128403529 4985 spin.kex = 406.843250675648 4986 4987 # Low precision optimisation. 4988 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 4989 4990 # Monte Carlo simulations. 4991 self.interpreter.monte_carlo.setup(number=2) 4992 self.interpreter.monte_carlo.create_data(method='back_calc') 4993 self.interpreter.monte_carlo.initial_values() 4994 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 4995 self.interpreter.monte_carlo.error_analysis() 4996 4997 # Plot the dispersion curves. 4998 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 4999 5000 # Save the results. 5001 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5002 5003 # Printout. 5004 print("\n\nOptimised parameters:\n") 5005 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5006 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5007 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5008 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5009 print("%-20s %20.15g" % ("pA", spin.pA)) 5010 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5011 print("%-20s %20.15g" % ("kex", spin.kex)) 5012 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5013 5014 # Checks for residue :9. 5015 self.assertAlmostEqual(spin.r2[r20_key1], 6.69107911078939, 2) 5016 self.assertAlmostEqual(spin.r2[r20_key2], 6.99888898689085, 2) 5017 self.assertAlmostEqual(spin.r2[r20_key3], 5.52012880268077, 2) 5018 self.assertAlmostEqual(spin.pA, 0.946990967372467, 4) 5019 self.assertAlmostEqual(spin.dwH, -0.265308128403529, 3) 5020 self.assertAlmostEqual(spin.kex/1000, 406.843250675648/1000, 2) 5021 self.assertAlmostEqual(spin.chi2, 50.3431330819767, 1)
5022 5023
5025 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5026 5027 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5028 5029 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5030 5031 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5032 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5033 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5034 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5035 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5036 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5037 - pA = 0.943125351763911, 5038 - dw = 4.421827493809807, 5039 - dwH = -0.272637034755752, 5040 - kex = 360.609744568697238, 5041 - chi2 = 162.589570340050813. 5042 """ 5043 5044 # Base data setup. 5045 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5046 5047 # Alias the spin. 5048 spin = return_spin(":9@N") 5049 5050 # The R20 keys. 5051 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5052 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5053 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5054 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5055 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5056 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5057 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5058 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5059 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5060 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5061 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5062 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5063 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5064 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5065 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5066 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5067 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5068 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5069 5070 # Set the initial parameter values. 5071 spin.r2 = { 5072 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5073 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5074 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5075 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5076 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5077 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5078 } 5079 spin.pA = 0.943129019477673 5080 spin.dw = 4.42209952545181 5081 spin.dwH = -0.27258970590969 5082 spin.kex = 360.516132791038 5083 5084 # Low precision optimisation. 5085 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=10) 5086 5087 # Monte Carlo simulations. 5088 self.interpreter.monte_carlo.setup(number=2) 5089 self.interpreter.monte_carlo.create_data(method='back_calc') 5090 self.interpreter.monte_carlo.initial_values() 5091 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5092 self.interpreter.monte_carlo.error_analysis() 5093 5094 # Plot the dispersion curves. 5095 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5096 5097 # Save the results. 5098 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5099 5100 # Printout. 5101 print("\n\nOptimised parameters:\n") 5102 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5103 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5104 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5105 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5106 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5107 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5108 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5109 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5110 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5111 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5112 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5113 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5114 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5115 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5116 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5117 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5118 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5119 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5120 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5121 print("%-20s %20.15g" % ("pA", spin.pA)) 5122 print("%-20s %20.15g" % ("dw", spin.dw)) 5123 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5124 print("%-20s %20.15g" % ("kex", spin.kex)) 5125 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5126 5127 # Checks for residue :9. 5128 self.assertAlmostEqual(spin.r2[r20_key1], 6.67288025927458, 4) 5129 self.assertAlmostEqual(spin.r2[r20_key2], 6.98951408255098, 4) 5130 self.assertAlmostEqual(spin.r2[r20_key3], 5.52959273852704, 4) 5131 self.assertAlmostEqual(spin.r2[r20_key4], 8.39471048876782, 4) 5132 self.assertAlmostEqual(spin.r2[r20_key5], 8.89290699178799, 4) 5133 self.assertAlmostEqual(spin.r2[r20_key6], 10.4077068723693, 4) 5134 self.assertAlmostEqual(spin.r2[r20_key7], 5.93611174376373, 4) 5135 self.assertAlmostEqual(spin.r2[r20_key8], 6.71735669582514, 4) 5136 self.assertAlmostEqual(spin.r2[r20_key9], 6.83835225518265, 4) 5137 self.assertAlmostEqual(spin.r2[r20_key10], 8.59615074668922, 4) 5138 self.assertAlmostEqual(spin.r2[r20_key11], 10.6512137889291, 4) 5139 self.assertAlmostEqual(spin.r2[r20_key12], 12.5710822919109, 4) 5140 self.assertAlmostEqual(spin.r2[r20_key13], 7.85956711501608, 4) 5141 self.assertAlmostEqual(spin.r2[r20_key14], 8.41891642907918, 4) 5142 self.assertAlmostEqual(spin.r2[r20_key15], 11.2362089223038, 4) 5143 self.assertAlmostEqual(spin.r2[r20_key16], 9.1965486378935, 4) 5144 self.assertAlmostEqual(spin.r2[r20_key17], 9.86031627358462, 4) 5145 self.assertAlmostEqual(spin.r2[r20_key18], 11.9752375592575, 4) 5146 self.assertAlmostEqual(spin.pA, 0.943129019477673, 4) 5147 self.assertAlmostEqual(spin.dw, 4.42209952545181, 4) 5148 self.assertAlmostEqual(spin.dwH, -0.27258970590969, 4) 5149 self.assertAlmostEqual(spin.kex/1000, 360.516132791038/1000, 4) 5150 self.assertAlmostEqual(spin.chi2/1000, 162.511988511609/1000, 3)
5151 5152
5154 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5155 5156 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5157 5158 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5159 5160 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5161 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5162 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5163 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5164 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5165 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5166 - pA = 0.943125351763911, 5167 - dw = 4.421827493809807, 5168 - dwH = -0.272637034755752, 5169 - kex = 360.609744568697238, 5170 - chi2 = 162.589570340050813. 5171 """ 5172 5173 # Base data setup. 5174 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5175 5176 # Alias the spin. 5177 spin = return_spin(":9@N") 5178 5179 # The R20 keys. 5180 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5181 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5182 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5183 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5184 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5185 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5186 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5187 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5188 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5189 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5190 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5191 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5192 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5193 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5194 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5195 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5196 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5197 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5198 5199 # Set the initial parameter values. 5200 spin.r2 = { 5201 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5202 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5203 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5204 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5205 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5206 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5207 } 5208 spin.pA = 0.943129019477673 5209 spin.dw = 4.42209952545181 5210 spin.dwH = -0.27258970590969 5211 spin.kex = 360.516132791038 5212 5213 # Calc the chi2 values at these parameters. 5214 self.interpreter.minimise.calculate(verbosity=1) 5215 5216 # Printout. 5217 print("\n\nOptimised parameters:\n") 5218 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5219 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5220 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5221 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5222 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5223 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5224 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5225 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5226 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5227 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5228 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5229 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5230 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5231 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5232 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5233 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5234 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5235 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5236 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5237 print("%-20s %20.15g" % ("pA", spin.pA)) 5238 print("%-20s %20.15g" % ("dw", spin.dw)) 5239 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5240 print("%-20s %20.15g" % ("kex", spin.kex)) 5241 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5242 5243 # Checks for residue :9. 5244 self.assertAlmostEqual(spin.chi2/1000, 162.511988511609/1000, 3)
5245 5246
5248 """Check of all possible dispersion graphs from optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5249 5250 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5251 5252 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5253 5254 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5255 - 0.483 0.89623903 2.4503699912708878 5256 - 0.545 1.1694838 5257 - 0.545 1.1761503 5258 - 0.622 1.294 5259 - 0.669 1.5176493 5260 - 0.722 1.6238791 5261 - 0.813 1.9395758 5262 - 1.011 2.3558415 10.547000429321157 5263 """ 5264 5265 # Base data setup. 5266 model = 'TSMFK01' 5267 expfolder = "acbp_cpmg_disp_048MGuHCl_40C_041223" 5268 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model=model, expfolder=expfolder) 5269 5270 # Alias the spins. 5271 res61L = cdp.mol[0].res[0].spin[0] 5272 5273 # The R20 keys. 5274 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5275 5276 # Set the initial parameter values. 5277 res61L.r2a = {r20_key1: 8.0} 5278 res61L.dw = 6.5 5279 res61L.k_AB = 2.5 5280 5281 # Low precision optimisation. 5282 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5283 5284 # Start testing all possible combinations of graphs. 5285 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 5286 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 5287 interpolate_types = [INTERPOLATE_DISP] 5288 5289 # Write to temp folder. 5290 result_dir_name = ds.tmpdir 5291 result_folders = [model] 5292 spin_id = ":61@N" 5293 5294 # Loop through all possible combinations of y_axis, x_axis and interpolation. 5295 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder+sep+'check_graphs' 5296 5297 for result_folder in result_folders: 5298 for y_axis in y_axis_types: 5299 for x_axis in x_axis_types: 5300 for interpolate in interpolate_types: 5301 # Determine file name: 5302 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 5303 5304 # Make the file name. 5305 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 5306 5307 # Write the curves. 5308 dir = result_dir_name+sep+result_folder 5309 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 5310 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 5311 5312 # Get the file path. 5313 file_path = get_file_path(file_name, dir) 5314 5315 # Test the plot file exists. 5316 print("Testing file access to graph: %s"%file_path) 5317 self.assert_(access(file_path, F_OK)) 5318 5319 # Now open, and compare content, line by line. 5320 file_prod = open(file_path) 5321 lines_prod = file_prod.readlines() 5322 file_prod.close() 5323 5324 # Define file to compare against. 5325 dir_comp = data_path+sep+result_folder 5326 file_path_comp = get_file_path(file_name, dir_comp) 5327 file_comp = open(file_path_comp) 5328 lines_comp = file_comp.readlines() 5329 file_comp.close() 5330 5331 ## Assert number of lines is equal. 5332 self.assertEqual(len(lines_prod), len(lines_comp)) 5333 for j in range(len(lines_prod)): 5334 # Make the string test 5335 first_char = lines_prod[j][0] 5336 if first_char in ["@", "&"]: 5337 self.assertEqual(lines_prod[j], lines_comp[j]) 5338 else: 5339 # Split string in x, y, error. 5340 # The error would change per run. 5341 x_prod, y_prod, y_prod_err = lines_prod[j].split() 5342 x_comp, y_comp, y_comp_err = lines_comp[j].split() 5343 self.assertAlmostEqual(float(x_prod), float(x_comp)) 5344 self.assertAlmostEqual(float(y_prod), float(y_comp)) 5345 self.assertAlmostEqual(float(y_prod_err), float(y_comp_err))
5346 5347
5349 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5350 5351 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5352 """ 5353 5354 # Base data setup. 5355 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5356 5357 # Alias the spins. 5358 res61L = cdp.mol[0].res[0].spin[0] 5359 5360 # The R20 keys. 5361 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5362 5363 # Set the initial parameter values. 5364 res61L.r2 = {r20_key1: 8.0} 5365 res61L.pA = 0.9 5366 res61L.dw = 6.0 5367 res61L.kex = 600.0 5368 5369 # Low precision optimisation. 5370 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5371 5372 # Printout. 5373 print("\n\nOptimised parameters:\n") 5374 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5375 print("%-20s %20.15g" % ("R2 (600 MHz)", res61L.r2[r20_key1])) 5376 print("%-20s %20.15g" % ("pA", res61L.pA)) 5377 print("%-20s %20.15g" % ("dw", res61L.dw)) 5378 print("%-20s %20.15g" % ("kex", res61L.kex)) 5379 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5380 5381 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5382 self.assertAlmostEqual(res61L.r2[r20_key1], 8.69277980194016, 4) 5383 self.assertAlmostEqual(res61L.pA, 0.9943781590842946, 5) 5384 self.assertAlmostEqual(res61L.dw, 6.389453131263374, 3) 5385 self.assertAlmostEqual(res61L.kex, 609.262167216419, 0) 5386 self.assertAlmostEqual(res61L.chi2, 65.99987828889657, 5) 5387 5388 # Test the conversion to k_AB from kex and pA. 5389 self.assertEqual(res61L.k_AB, res61L.kex * (1.0 - res61L.pA)) 5390 5391 # Test the conversion to k_BA from kex and pA. 5392 self.assertEqual(res61L.k_BA, res61L.kex * res61L.pA)
5393 5394
5396 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5397 5398 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5399 """ 5400 5401 # Base data setup. 5402 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72 full', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5403 5404 # Alias the spins. 5405 res61L = cdp.mol[0].res[0].spin[0] 5406 5407 # The R20 keys. 5408 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5409 5410 # Set the initial parameter values. 5411 res61L.r2a = {r20_key1: 8.0} 5412 res61L.r2b = {r20_key1: 105.0} 5413 res61L.pA = 0.9 5414 res61L.dw = 6.0 5415 res61L.kex = 500.0 5416 5417 # Low precision optimisation. 5418 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5419 5420 # Printout. 5421 print("\n\nOptimised parameters:\n") 5422 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5423 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5424 print("%-20s %20.15g" % ("R2B (600 MHz)", res61L.r2b[r20_key1])) 5425 print("%-20s %20.15g" % ("pA", res61L.pA)) 5426 print("%-20s %20.15g" % ("dw", res61L.dw)) 5427 print("%-20s %20.15g" % ("kex", res61L.kex)) 5428 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5429 5430 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5431 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.044428899438309, 0) 5432 self.assertAlmostEqual(res61L.r2b[r20_key1], 105.11894506392449, -2) 5433 self.assertAlmostEqual(res61L.pA, 0.992066883657578, 2) 5434 self.assertAlmostEqual(res61L.dw, 6.389453586338883, 3) 5435 self.assertAlmostEqual(res61L.kex, 513.483608742063, -2) 5436 self.assertAlmostEqual(res61L.chi2, 65.99987828890289, 5)
5437 5438
5440 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5441 5442 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5443 5444 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5445 5446 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5447 - 0.483 0.89623903 2.4503699912708878 5448 - 0.545 1.1694838 5449 - 0.545 1.1761503 5450 - 0.622 1.294 5451 - 0.669 1.5176493 5452 - 0.722 1.6238791 5453 - 0.813 1.9395758 5454 - 1.011 2.3558415 10.547000429321157 5455 """ 5456 5457 # Base data setup. 5458 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5459 5460 # Alias the spins. 5461 res61L = cdp.mol[0].res[0].spin[0] 5462 5463 # The R20 keys. 5464 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5465 5466 # Set the initial parameter values. 5467 res61L.r2a = {r20_key1: 8.0} 5468 res61L.dw = 6.5 5469 res61L.k_AB = 2.5 5470 5471 # Low precision optimisation. 5472 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5473 5474 # Printout. 5475 print("\n\nOptimised parameters:\n") 5476 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5477 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5478 print("%-20s %20.15g" % ("dw", res61L.dw)) 5479 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 5480 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5481 5482 # Checks for residue :61. Reference values from paper 5483 5484 self.assertAlmostEqual(res61L.k_AB, 2.45, 1)
5485 5486
5488 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5489 5490 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 1.01 M GuHCl (guanidine hydrochloride). 5491 5492 The comparison is to Figure 2, which is for dataset with 1 M GuHCl. The reported results are expected to be in rad.s^-1. Conversion into relax stored values is preferably. 5493 5494 Representative 15N CPMG relaxation dispersion curve measured on the cross peaks from residue L61 in folded ACBP at pH 5.3, 1 M GuHCl, and 40C: 5495 5496 1. The dotted line represents a residue-specific fit of all parameters in Eq. 1: 5497 - k_AB = 11.3 +/- 0.7 s^-1, 5498 - dw = (2.45 +/- 0.09) * 10^3 s^-1, 5499 - R2 = 8.0 +/- 0.5 s^-1. 5500 5501 2. The solid line represents a global fit of k_AB to all protein residues and a residue-specific fit of dw and R2.: 5502 - k_AB = 10.55 +/- 0.08 s^-1, 5503 - dw = (2.44 +/- 0.08) * 10^3 s^-1, 5504 - R2 = 8.4 +/- 0.3 s^-1. 5505 5506 Conversion of paper results to relax results is performed by: 5507 5508 - dw(ppm) = dw(rad.s^-1) * 10^6 * 1/(2*pi) * (gyro1H/(gyro15N*spectrometer_freq)) = 2.45E3 * 1E6 / (2 * math.pi) * (26.7522212E7/(-2.7126E7 * 599.8908622E6)) = -6.41 ppm. 5509 5510 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5511 5512 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5513 - 0.483 0.89623903 2.4503699912708878 5514 - 0.545 1.1694838 5515 - 0.545 1.1761503 5516 - 0.622 1.294 5517 - 0.669 1.5176493 5518 - 0.722 1.6238791 5519 - 0.813 1.9395758 5520 - 1.011 2.3558415 10.547000429321157 5521 """ 5522 5523 # Base data setup. 5524 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_101MGuHCl_40C_041223") 5525 5526 # Alias the spins. 5527 res61L = cdp.mol[0].res[0].spin[0] 5528 5529 # The R20 keys. 5530 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086270e6) 5531 5532 # Set the initial parameter values. 5533 res61L.r2a = {r20_key1: 8.0} 5534 res61L.dw = 6.5 5535 res61L.k_AB = 11.0 5536 5537 # Low precision optimisation. 5538 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5539 5540 # Printout. 5541 print("\n\nOptimised parameters:\n") 5542 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5543 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5544 print("%-20s %20.15g" % ("dw", res61L.dw)) 5545 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 5546 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5547 5548 # Checks for residue :61. Reference values from paper 5549 5550 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.4, 0) 5551 self.assertAlmostEqual(res61L.dw, 6.41, 0) 5552 self.assertAlmostEqual(res61L.k_AB, 10.55, 0)
5553 5554
5555 - def test_lm63_3site_synthetic(self):
5556 """Test the 'LM63 3-site' dispersion model using the pure noise-free synthetic data.""" 5557 5558 # The path to the data files. 5559 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'lm63_3site' 5560 5561 # Load the state file. 5562 self.interpreter.reset() 5563 self.interpreter.state.load(data_path+sep+'r2eff_values') 5564 5565 # A new data pipe. 5566 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to='LM63 3-site', bundle_to='relax_disp') 5567 self.interpreter.pipe.switch(pipe_name='LM63 3-site') 5568 5569 # Set up the model data. 5570 self.interpreter.relax_disp.select_model(model='LM63 3-site') 5571 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to='LM63 3-site', param='r2eff') 5572 self.interpreter.spin.isotope('15N') 5573 5574 # Alias the spins. 5575 spin1 = return_spin(":1") 5576 spin2 = return_spin(":2") 5577 5578 # The R20 keys. 5579 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5580 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5581 5582 # Manually set the parameter values. 5583 spin1.r2 = {r20_key1: 12.0, r20_key2: 12.0} 5584 spin1.phi_ex_B = 0.1 5585 spin1.phi_ex_C = 0.5 5586 spin1.kB = 1500.0 5587 spin1.kC = 2500.0 5588 spin2.r2 = {r20_key1: 15.0, r20_key2: 15.0} 5589 spin2.phi_ex_B = 0.1 5590 spin2.phi_ex_C = 0.5 5591 spin2.kB = 1500.0 5592 spin2.kC = 2500.0 5593 5594 # Low precision optimisation. 5595 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5596 5597 # Monte Carlo simulations. 5598 self.interpreter.monte_carlo.setup(number=3) 5599 self.interpreter.monte_carlo.create_data(method='back_calc') 5600 self.interpreter.monte_carlo.initial_values() 5601 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-2, grad_tol=None, max_iter=10, constraints=True, scaling=True, verbosity=1) 5602 self.interpreter.monte_carlo.error_analysis() 5603 5604 # Save the results. 5605 self.interpreter.results.write(file='devnull', compress_type=1, force=True) 5606 5607 # The model checks. 5608 print("\n\nOptimised parameters:\n") 5609 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 5610 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 5611 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 5612 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin1.phi_ex_B, spin2.phi_ex_B)) 5613 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin1.phi_ex_C, spin2.phi_ex_C)) 5614 print("%-20s %20.15g %20.15g" % ("kB", spin1.kB, spin2.kB)) 5615 print("%-20s %20.15g %20.15g" % ("kC", spin1.kC, spin2.kC)) 5616 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 5617 self.assertAlmostEqual(spin1.r2[r20_key1], 12.0, 2) 5618 self.assertAlmostEqual(spin1.r2[r20_key2], 12.0, 2) 5619 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 5620 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 5621 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 5622 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 5623 self.assertAlmostEqual(spin1.chi2, 0.0, 3) 5624 self.assertAlmostEqual(spin2.r2[r20_key1], 15.0, 3) 5625 self.assertAlmostEqual(spin2.r2[r20_key2], 15.0, 3) 5626 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 5627 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 5628 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 5629 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 5630 self.assertAlmostEqual(spin2.chi2, 0.0, 3)
5631 5632
5633 - def test_m61_data_to_m61(self):
5634 """Test the relaxation dispersion 'M61' model curve fitting to fixed time synthetic data.""" 5635 5636 # Fixed time variable. 5637 ds.fixed = True 5638 5639 # Execute the script. 5640 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 5641 5642 # The original parameters. 5643 i0 = [100000.0, 20000.0] 5644 r1rho_prime = [2.25, 24.0] 5645 pA = 0.7 5646 kex = 1000.0 5647 delta_omega = [1.0, 2.0] 5648 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 5649 phi_ex = [] 5650 for i in range(2): 5651 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 5652 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 5653 5654 # Switch to the 'R2eff' model data pipe, then check for each spin. 5655 self.interpreter.pipe.switch('R2eff - relax_disp') 5656 spin_index = 0 5657 for spin, spin_id in spin_loop(return_id=True): 5658 # Printout. 5659 print("\nSpin %s." % spin_id) 5660 5661 # Check the fitted parameters. 5662 for i in range(len(keys)): 5663 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 5664 5665 # Increment the spin index. 5666 spin_index += 1 5667 5668 # The R20 keys. 5669 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 5670 5671 # Switch to the 'M61' model data pipe, then check for each spin. 5672 self.interpreter.pipe.switch('M61 - relax_disp') 5673 spin_index = 0 5674 for spin, spin_id in spin_loop(return_id=True): 5675 # Printout. 5676 print("\nSpin %s." % spin_id) 5677 5678 # Check the fitted parameters. 5679 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 5680 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 5681 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 5682 5683 # Increment the spin index. 5684 spin_index += 1
5685 5686
5687 - def test_m61_exp_data_to_m61(self):
5688 """Test the relaxation dispersion 'M61' model curve fitting to the full exponential synthetic data.""" 5689 5690 # Fixed time variable. 5691 ds.fixed = False 5692 5693 # Single spin optimisation. 5694 ds.single = True 5695 5696 # Execute the script. 5697 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 5698 5699 # The original parameters. 5700 i0 = [100000.0, 20000.0] 5701 r1rho_prime = [2.25, 24.0] 5702 pA = 0.7 5703 kex = 1000.0 5704 delta_omega = [1.0, 2.0] 5705 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 5706 phi_ex = [] 5707 for i in range(2): 5708 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 5709 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 5710 5711 # Switch to the 'R2eff' model data pipe, then check for each spin. 5712 self.interpreter.pipe.switch('R2eff - relax_disp') 5713 spin_index = 0 5714 for spin, spin_id in spin_loop(return_id=True): 5715 # Printout. 5716 print("\nSpin %s." % spin_id) 5717 5718 # Check the fitted parameters. 5719 for i in range(len(keys)): 5720 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 5721 5722 # Increment the spin index. 5723 spin_index += 1 5724 5725 # The R20 keys. 5726 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 5727 5728 # Switch to the 'M61' model data pipe, then check for each spin. 5729 self.interpreter.pipe.switch('M61 - relax_disp') 5730 spin_index = 0 5731 for spin, spin_id in spin_loop(return_id=True): 5732 # Printout. 5733 print("\nSpin %s." % spin_id) 5734 5735 # Check the fitted parameters. 5736 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 5737 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 5738 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 5739 5740 # Increment the spin index. 5741 spin_index += 1
5742 5743
5744 - def xxx_test_m61b_data_to_m61b(self):
5745 """Test the relaxation dispersion 'M61 skew' model curve fitting to fixed time synthetic data.""" 5746 5747 # Execute the script. 5748 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61b.py') 5749 5750 # The original parameters. 5751 i0 = [100000.0, 20000.0] 5752 r1rho_prime = [10.0, 24.0] 5753 pA = 0.95 5754 kex = 2000.0 5755 delta_omega = [1.0, 2.0] 5756 5757 # The R20 keys. 5758 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 5759 5760 # Switch to the 'M61 skew' model data pipe, then check for each spin. 5761 self.interpreter.pipe.switch("%s - relax_disp" % MODEL_M61B) 5762 spin_index = 0 5763 for spin, spin_id in spin_loop(return_id=True): 5764 # Printout. 5765 print("\nSpin %s." % spin_id) 5766 5767 # Check the fitted parameters. 5768 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 5769 self.assertAlmostEqual(spin.pA, pA, 2) 5770 self.assertAlmostEqual(spin.dw, dw[spin_index], 2) 5771 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 5772 5773 # Increment the spin index. 5774 spin_index += 1
5775 5776
5778 """Test that all models which can nest, have all their parameters converted.""" 5779 5780 # Set the experiment type. 5781 cdp.exp_type_list = EXP_TYPE_LIST 5782 5783 # Get info for all models. 5784 all_models_info = models_info(models=MODEL_LIST_FULL) 5785 5786 # Loop over all models. 5787 print("Printing the listed of nested models for each model.") 5788 print("#########################################") 5789 for model_info in all_models_info: 5790 print("%s"%model_info.model), 5791 print("<-"), 5792 nest_list = model_info.nest_list 5793 if nest_list == None: 5794 nest_list = ["None"] 5795 print(', '.join(map(str, nest_list))) 5796 5797 # Skip if there is no model to nest from. 5798 if nest_list == ["None"]: 5799 continue 5800 5801 # Assign params to variable. 5802 model_params = model_info.params 5803 5804 # Now loop over the nested models. 5805 for nested_model in nest_list: 5806 # Get the params for the nested model. 5807 nested_model_params = MODEL_PARAMS[nested_model] 5808 5809 # Get the dictionary of parameter conversion. 5810 par_dic = nesting_param(model_params=model_params, nested_model_params=nested_model_params) 5811 5812 # Test the number of elements in the dictionary. 5813 self.assertEqual(len(par_dic), len(model_params)) 5814 5815 # Loop over dictionary. 5816 for param, param_conv in par_dic.iteritems(): 5817 if param != param_conv: 5818 print("Model:'%s', Nested model:'%s', Copying '%s' to '%s'." % (model_info.model, nested_model, param_conv, param)) 5819 self.assertNotEqual(param_conv, None)
5820 5821
5822 - def test_ns_mmq_3site(self):
5823 """Compare the 'NS MMQ 3-site' dispersion model to synthetic data from cpmg_fit.""" 5824 5825 # Execute the script. 5826 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site.py') 5827 5828 # Check the chi-squared value. 5829 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
5830 5831
5832 - def test_ns_mmq_3site_linear(self):
5833 """Compare the 'NS MMQ 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 5834 5835 # Execute the script. 5836 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site_linear.py') 5837 5838 # Check the chi-squared value. 5839 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
5840 5841
5842 - def test_ns_r1rho_3site(self):
5843 """Compare the 'NS R1rho 3-site' dispersion model to synthetic data from cpmg_fit.""" 5844 5845 # Execute the script. 5846 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site.py') 5847 5848 # Check the chi-squared value. 5849 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 136.13141468674999, 3)
5850 5851
5852 - def test_ns_r1rho_3site_linear(self):
5853 """Compare the 'NS R1rho 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 5854 5855 # Execute the script. 5856 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site_linear.py') 5857 5858 # Check the chi-squared value. 5859 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 0.030959849811015544, 3)
5860 5861
5862 - def test_r1rho_kjaergaard_auto(self):
5863 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 5864 5865 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 5866 5867 This uses the automatic analysis. 5868 5869 """ 5870 5871 # Cluster residues 5872 cluster_ids = [ 5873 ":13@N", 5874 ":15@N", 5875 ":16@N", 5876 ":25@N", 5877 ":26@N", 5878 ":28@N", 5879 ":39@N", 5880 ":40@N", 5881 ":41@N", 5882 ":43@N", 5883 ":44@N", 5884 ":45@N", 5885 ":49@N", 5886 ":52@N", 5887 ":53@N"] 5888 5889 # Load the data. 5890 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 5891 5892 # Test some of the sequence. 5893 self.assertEqual(len(cdp.mol), 1) 5894 self.assertEqual(cdp.mol[0].name, None) 5895 self.assertEqual(len(cdp.mol[0].res), 48) 5896 5897 # Test the chemical shift data. 5898 cs = [122.223, 122.162, 114.250, 125.852, 118.626, 117.449, 119.999, 122.610, 118.602, 118.291, 115.393, 5899 121.288, 117.448, 116.378, 116.316, 117.263, 122.211, 118.748, 118.103, 119.421, 119.317, 119.386, 117.279, 5900 122.103, 120.038, 116.698, 111.811, 118.639, 118.285, 121.318, 117.770, 119.948, 119.759, 118.314, 118.160, 5901 121.442, 118.714, 113.080, 125.706, 119.183, 120.966, 122.361, 126.675, 117.069, 120.875, 109.372, 119.811, 126.048] 5902 5903 i = 0 5904 for spin, spin_id in spin_loop(return_id=True): 5905 # Check the chemical shift. 5906 self.assertEqual(spin.chemical_shift, cs[i]) 5907 5908 # Increment the index. 5909 i += 1 5910 5911 # Initialize counter 5912 i = 0 5913 j = 0 5914 # Count instances of select/deselect 5915 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 5916 if curspin.select == True: 5917 i += 1 5918 if curspin.select == False: 5919 j += 1 5920 5921 # Test number of selected/deselected spins. 5922 self.assertEqual(i, len(cluster_ids)) 5923 self.assertEqual(j, 48-len(cluster_ids)) 5924 5925 # Check the initial setup. 5926 self.assertEqual(cdp.mol[0].res[7].num, 13) 5927 self.assertEqual(cdp.mol[0].res[7].spin[0].kex, ds.guess[':13@N'][6]) 5928 self.assertEqual(cdp.mol[0].res[7].spin[0].ri_data['R1'], ds.ref[':13@N'][2]) 5929 5930 self.assertEqual(cdp.mol[0].res[9].num, 15) 5931 self.assertEqual(cdp.mol[0].res[9].spin[0].kex, ds.guess[':15@N'][6]) 5932 self.assertEqual(cdp.mol[0].res[9].spin[0].ri_data['R1'], ds.ref[':15@N'][2]) 5933 5934 self.assertEqual(cdp.mol[0].res[10].num, 16) 5935 self.assertEqual(cdp.mol[0].res[10].spin[0].kex, ds.guess[':16@N'][6]) 5936 self.assert_(hasattr(cdp.mol[0].res[10].spin[0], 'ri_data')) 5937 5938 self.assertEqual(cdp.mol[0].res[16].num, 25) 5939 self.assertEqual(cdp.mol[0].res[16].spin[0].kex, ds.guess[':25@N'][6]) 5940 self.assert_(hasattr(cdp.mol[0].res[16].spin[0], 'ri_data')) 5941 5942 self.assertEqual(cdp.mol[0].res[17].num, 26) 5943 self.assertEqual(cdp.mol[0].res[17].spin[0].kex, ds.guess[':26@N'][6]) 5944 self.assert_(hasattr(cdp.mol[0].res[17].spin[0], 'ri_data')) 5945 5946 self.assertEqual(cdp.mol[0].res[19].num, 28) 5947 self.assertEqual(cdp.mol[0].res[19].spin[0].kex, ds.guess[':28@N'][6]) 5948 self.assert_(hasattr(cdp.mol[0].res[19].spin[0], 'ri_data')) 5949 5950 self.assertEqual(cdp.mol[0].res[29].num, 39) 5951 self.assertEqual(cdp.mol[0].res[29].spin[0].kex, ds.guess[':39@N'][6]) 5952 self.assert_(hasattr(cdp.mol[0].res[29].spin[0], 'ri_data')) 5953 5954 self.assertEqual(cdp.mol[0].res[30].num, 40) 5955 self.assertEqual(cdp.mol[0].res[30].spin[0].kex, ds.guess[':40@N'][6]) 5956 self.assert_(hasattr(cdp.mol[0].res[30].spin[0], 'ri_data')) 5957 5958 self.assertEqual(cdp.mol[0].res[31].num, 41) 5959 self.assertEqual(cdp.mol[0].res[31].spin[0].kex, ds.guess[':41@N'][6]) 5960 self.assert_(hasattr(cdp.mol[0].res[31].spin[0], 'ri_data')) 5961 5962 self.assertEqual(cdp.mol[0].res[33].num, 43) 5963 self.assertEqual(cdp.mol[0].res[33].spin[0].kex, ds.guess[':43@N'][6]) 5964 self.assert_(hasattr(cdp.mol[0].res[33].spin[0], 'ri_data')) 5965 5966 self.assertEqual(cdp.mol[0].res[34].num, 44) 5967 self.assertEqual(cdp.mol[0].res[34].spin[0].kex, ds.guess[':44@N'][6]) 5968 self.assert_(hasattr(cdp.mol[0].res[34].spin[0], 'ri_data')) 5969 5970 self.assertEqual(cdp.mol[0].res[35].num, 45) 5971 self.assertEqual(cdp.mol[0].res[35].spin[0].kex, ds.guess[':45@N'][6]) 5972 self.assert_(hasattr(cdp.mol[0].res[35].spin[0], 'ri_data')) 5973 5974 self.assertEqual(cdp.mol[0].res[38].num, 49) 5975 self.assertEqual(cdp.mol[0].res[38].spin[0].kex, ds.guess[':49@N'][6]) 5976 self.assert_(hasattr(cdp.mol[0].res[38].spin[0], 'ri_data')) 5977 5978 self.assertEqual(cdp.mol[0].res[41].num, 52) 5979 self.assertEqual(cdp.mol[0].res[41].spin[0].kex, ds.guess[':52@N'][6]) 5980 self.assert_(hasattr(cdp.mol[0].res[41].spin[0], 'ri_data')) 5981 5982 self.assertEqual(cdp.mol[0].res[42].num, 53) 5983 self.assertEqual(cdp.mol[0].res[42].spin[0].kex, ds.guess[':53@N'][6]) 5984 self.assert_(hasattr(cdp.mol[0].res[42].spin[0], 'ri_data')) 5985 5986 # The dispersion models. 5987 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 5988 5989 # The grid search size (the number of increments per dimension). 5990 GRID_INC = 4 5991 5992 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 5993 MC_NUM = 3 5994 5995 # Model selection technique. 5996 MODSEL = 'AIC' 5997 5998 # Execute the auto-analysis (fast). 5999 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6000 OPT_FUNC_TOL = 1e-1 6001 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6002 OPT_MAX_ITERATIONS = 1000 6003 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6004 6005 result_dir_name = ds.tmpdir 6006 6007 # Make all spins free 6008 for curspin in cluster_ids: 6009 self.interpreter.relax_disp.cluster('free spins', curspin) 6010 # Shut them down 6011 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 6012 6013 # Select only a subset of spins for global fitting 6014 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 6015 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 6016 6017 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 6018 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 6019 6020 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 6021 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 6022 6023 # Run the analysis. 6024 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 6025 6026 # Check the kex value of residue 52 6027 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 6028 6029 # Print results for each model. 6030 print("\n\n################") 6031 print("Printing results") 6032 print("################\n") 6033 for model in MODELS: 6034 # Skip R2eff model. 6035 if model == MODEL_R2EFF: 6036 continue 6037 6038 # Switch to pipe. 6039 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 6040 print("\nModel: %s" % (model)) 6041 6042 # Loop over the spins. 6043 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6044 # Generate spin string. 6045 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 6046 6047 # Loop over the parameters. 6048 print("Optimised parameters for spin: %s" % (spin_string)) 6049 for param in cur_spin.params + ['chi2']: 6050 # Get the value. 6051 if param in ['r1', 'r2']: 6052 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 6053 # Generate the R20 key. 6054 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 6055 6056 # Get the value. 6057 value = getattr(cur_spin, param)[r20_key] 6058 6059 # Print value. 6060 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 6061 6062 # For all other parameters. 6063 else: 6064 # Get the value. 6065 value = getattr(cur_spin, param) 6066 6067 # Print value. 6068 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 6069 6070 # Print the final pipe. 6071 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % ('final')) 6072 print("\nFinal pipe")
6073 6074
6076 """Check of plot_disp_curves() function, after optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'R2eff' model. 6077 6078 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6079 6080 This uses the automatic analysis. 6081 6082 """ 6083 6084 # Cluster residues 6085 cluster_ids = [ 6086 ":52@N"] 6087 6088 # Load the data. 6089 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 6090 6091 # The dispersion models. 6092 MODELS = [MODEL_R2EFF] 6093 6094 # The grid search size (the number of increments per dimension). 6095 GRID_INC = 4 6096 6097 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6098 MC_NUM = 3 6099 6100 # Model selection technique. 6101 MODSEL = 'AIC' 6102 6103 # Execute the auto-analysis (fast). 6104 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6105 OPT_FUNC_TOL = 1e-1 6106 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6107 OPT_MAX_ITERATIONS = 1000 6108 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6109 6110 result_dir_name = ds.tmpdir 6111 6112 # Make all spins free 6113 for curspin in cluster_ids: 6114 self.interpreter.relax_disp.cluster('free spins', curspin) 6115 # Shut them down 6116 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 6117 6118 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 6119 6120 # Run the analysis. 6121 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 6122 6123 # Check the graphs produced. 6124 graph_comb = [ 6125 [Y_AXIS_R2_EFF, X_AXIS_DISP, INTERPOLATE_DISP], 6126 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_DISP], 6127 [Y_AXIS_R2_R1RHO, X_AXIS_W_EFF, INTERPOLATE_DISP], 6128 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_OFFSET] 6129 ] 6130 6131 # Define expected folder names. 6132 result_folders = MODELS 6133 6134 # Assign spin_id. 6135 spin_id = ':52@N' 6136 6137 # Loop over result folders. 6138 for result_folder in result_folders: 6139 # Skip the model R2eff, which does not produce graphs. 6140 if result_folder == MODEL_R2EFF: 6141 continue 6142 6143 # Loop over graphs. 6144 for y_axis, x_axis, interpolate in graph_comb: 6145 # Determine file name: 6146 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 6147 6148 # Make the file name. 6149 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 6150 6151 # Get the file path. 6152 file_path = get_file_path(file_name, result_dir_name+sep+result_folder) 6153 6154 print("Testing file access to graph: %s"%file_path) 6155 self.assert_(access(file_path, F_OK)) 6156 6157 # Start testing all possible combinations of graphs. 6158 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 6159 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 6160 interpolate_types = [INTERPOLATE_DISP, INTERPOLATE_OFFSET] 6161 6162 result_dir_name = ds.tmpdir 6163 6164 # Loop through all possible combinations of y_axis, x_axis and interpolation. 6165 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep+'check_graphs' 6166 6167 for result_folder in result_folders: 6168 # Skip the model R2eff, which does not produce graphs. 6169 if result_folder == MODEL_R2EFF: 6170 continue 6171 6172 for y_axis in y_axis_types: 6173 for x_axis in x_axis_types: 6174 for interpolate in interpolate_types: 6175 # Determine file name: 6176 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 6177 6178 # Make the file name. 6179 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 6180 6181 # Write the curves. 6182 dir = result_dir_name+sep+result_folder 6183 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 6184 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 6185 6186 # Get the file path. 6187 file_path = get_file_path(file_name, dir) 6188 6189 # Test the plot file exists. 6190 print("Testing file access to graph: %s"%file_path) 6191 self.assert_(access(file_path, F_OK)) 6192 6193 # Now open, and compare content, line by line. 6194 file_prod = open(file_path) 6195 lines_prod = file_prod.readlines() 6196 file_prod.close() 6197 6198 # Define file to compare against. 6199 dir_comp = data_path+sep+result_folder 6200 file_path_comp = get_file_path(file_name, dir_comp) 6201 file_comp = open(file_path_comp) 6202 lines_comp = file_comp.readlines() 6203 file_comp.close() 6204 6205 # Assert number of lines is equal. 6206 self.assertEqual(len(lines_prod), len(lines_comp)) 6207 for j in range(len(lines_prod)): 6208 # Make the string test 6209 first_char = lines_prod[j][0] 6210 if first_char in ["@", "&"]: 6211 self.assertEqual(lines_prod[j], lines_comp[j]) 6212 else: 6213 # Split string in x, y, error. 6214 # The error would change per run. 6215 x_prod, y_prod, y_prod_err = lines_prod[j].split() 6216 x_comp, y_comp, y_comp_err = lines_comp[j].split() 6217 self.assertAlmostEqual(float(x_prod), float(x_comp)) 6218 self.assertAlmostEqual(float(y_prod), float(y_comp))
6219 6220
6222 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 6223 6224 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6225 6226 This uses the automatic analysis, with missing loading R1. 6227 6228 """ 6229 6230 # Cluster residues 6231 cluster_ids = [ 6232 ":13@N", 6233 ":15@N", 6234 ":16@N", 6235 ":25@N", 6236 ":26@N", 6237 ":28@N", 6238 ":39@N", 6239 ":40@N", 6240 ":41@N", 6241 ":43@N", 6242 ":44@N", 6243 ":45@N", 6244 ":49@N", 6245 ":52@N", 6246 ":53@N"] 6247 6248 # Load the data. 6249 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 6250 6251 # The dispersion models. 6252 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 6253 6254 # The grid search size (the number of increments per dimension). 6255 GRID_INC = None 6256 6257 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6258 MC_NUM = 3 6259 6260 # Model selection technique. 6261 MODSEL = 'AIC' 6262 6263 # Execute the auto-analysis (fast). 6264 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6265 OPT_FUNC_TOL = 1e-25 6266 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6267 OPT_MAX_ITERATIONS = 10000000 6268 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6269 6270 result_dir_name = ds.tmpdir 6271 6272 # Make all spins free 6273 for curspin in cluster_ids: 6274 self.interpreter.relax_disp.cluster('free spins', curspin) 6275 # Shut them down 6276 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 6277 6278 # Select only a subset of spins for global fitting 6279 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 6280 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 6281 6282 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 6283 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 6284 6285 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 6286 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 6287 6288 # Point to directory with R2eff values, with 2000 MC simulations. 6289 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" 6290 6291 r1_fit = True 6292 6293 # Run the analysis. 6294 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, pre_run_dir=prev_data_path, r1_fit=r1_fit) 6295 6296 # Verify the data. 6297 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='MC2000')
6298 6299
6300 - def test_r2eff_read(self):
6301 """Test the operation of the relax_disp.r2eff_read user function.""" 6302 6303 # The path to the data files. 6304 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'800_MHz' 6305 6306 # Read the sequence data. 6307 self.interpreter.sequence.read(file='66.667.in', dir=data_path, res_num_col=1) 6308 6309 # The ID. 6310 id = 'test' 6311 6312 # Set up the metadata. 6313 self.interpreter.spectrometer.frequency(id=id, frq=800e6) 6314 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 6315 6316 # Try reading the file. 6317 self.interpreter.relax_disp.r2eff_read(id=id, file='66.667.in', dir=data_path, disp_frq=66.667, res_num_col=1, data_col=2, error_col=3) 6318 6319 # Check the global data. 6320 data = [ 6321 ['cpmg_frqs', {'test': 66.667}], 6322 ['cpmg_frqs_list', [66.667]], 6323 ['dispersion_points', 1], 6324 ['exp_type', {'test': 'SQ CPMG'}], 6325 ['exp_type_list', ['SQ CPMG']], 6326 ['spectrometer_frq', {'test': 800000000.0}], 6327 ['spectrometer_frq_count', 1], 6328 ['spectrometer_frq_list', [800000000.0]], 6329 ['spectrum_ids', ['test']] 6330 ] 6331 for name, value in data: 6332 # Does it exist? 6333 self.assert_(hasattr(cdp, name)) 6334 6335 # Check the object. 6336 obj = getattr(cdp, name) 6337 self.assertEqual(obj, value) 6338 6339 # Check the spin data. 6340 data = [ 6341 [1, 2.3035747e+04, 8.5467725e+01], 6342 [2, 9.9629762e+04, 2.8322033e+02], 6343 [3, 9.5663137e+04, 2.8632929e+02], 6344 [4, 1.7089893e+05, 3.1089428e+02], 6345 [5, 4.7323876e+04, 1.0084269e+02], 6346 [6, 2.0199122e+04, 1.0135220e+02], 6347 [7, 1.6655488e+05, 3.1609061e+02], 6348 [8, 9.0061074e+04, 1.9176585e+02], 6349 [10, 8.4726204e+04, 2.8898155e+02], 6350 [11, 1.5050233e+05, 4.3138029e+02], 6351 [12, 9.2998531e+04, 3.0440191e+02], 6352 [13, 1.6343507e+05, 3.3144097e+02], 6353 [14, 1.0137301e+05, 3.7314642e+02], 6354 [15, 8.3407837e+04, 1.6546473e+02], 6355 [16, 1.3819126e+05, 3.3388517e+02], 6356 [17, 1.1010490e+05, 3.5639222e+02], 6357 [18, 9.4324035e+04, 3.2343585e+02], 6358 [19, 1.1135179e+05, 3.0706671e+02], 6359 [20, 7.6339410e+04, 1.7377460e+02], 6360 [21, 6.2008453e+04, 1.7327150e+02], 6361 [22, 1.0590404e+05, 2.4814635e+02], 6362 [23, 1.0630198e+05, 2.3601100e+02], 6363 [24, 7.2996320e+04, 1.4952465e+02], 6364 [25, 9.5486742e+04, 2.7080766e+02], 6365 [26, 5.8067989e+04, 1.6820462e+02], 6366 [27, -1.7168510e+04, 2.2519560e+02], 6367 [28, 1.6891473e+05, 2.3497525e+02], 6368 [29, 9.4038555e+04, 2.0357593e+02], 6369 [30, 2.1386951e+04, 2.2153532e+02], 6370 [31, 9.3982899e+04, 2.0937056e+02], 6371 [32, 8.6097484e+04, 2.3868467e+02], 6372 [33, 1.0194337e+05, 2.7370704e+02], 6373 [34, 8.5683111e+04, 2.0838076e+02], 6374 [35, 8.6985768e+04, 2.0889310e+02], 6375 [36, 8.6011237e+04, 1.7498390e+02], 6376 [37, 1.0984097e+05, 2.7622998e+02], 6377 [38, 8.7017879e+04, 2.6547994e+02], 6378 [39, 9.1682649e+04, 5.2777676e+02], 6379 [40, 7.6370440e+04, 1.9873214e+02], 6380 [41, 9.1393531e+04, 2.4483824e+02], 6381 [42, 1.1017111e+05, 2.8020699e+02], 6382 [43, 9.4552366e+04, 3.4394150e+02], 6383 [44, 1.2858281e+05, 6.8449252e+02], 6384 [45, 7.4583525e+04, 1.9544210e+02], 6385 [46, 9.2087490e+04, 2.0491066e+02], 6386 [47, 9.7507255e+04, 2.5162839e+02], 6387 [48, 1.0033842e+05, 2.7566430e+02], 6388 [49, 1.3048305e+05, 2.6797466e+02], 6389 [50, 1.0546796e+05, 1.9304384e+02], 6390 [51, 9.3099697e+04, 2.0773311e+02], 6391 [52, 4.6863758e+04, 1.3169068e+02], 6392 [53, 6.1055806e+04, 1.5448477e+02], 6393 [55, 6.8629994e+04, 1.6868673e+02], 6394 [56, 1.1005552e+05, 2.1940465e+02], 6395 [57, 1.0572760e+05, 1.9768486e+02], 6396 [58, 1.1176950e+05, 3.0009610e+02], 6397 [59, 9.8758603e+04, 3.3803895e+02], 6398 [60, 9.9517201e+04, 3.5137994e+02], 6399 [61, 5.4357946e+04, 2.5896579e+02], 6400 [62, 1.0899978e+05, 2.8720371e+02], 6401 [63, 8.4549759e+04, 4.1401837e+02], 6402 [64, 5.5014550e+04, 2.1135781e+02], 6403 [65, 8.0569666e+04, 2.3249709e+02], 6404 [66, 1.2936610e+05, 3.5218725e+02], 6405 [67, 3.6438010e+04, 8.7924003e+01], 6406 [70, 3.8763157e+04, 1.3325040e+02], 6407 [71, 8.5711411e+04, 2.9316183e+02], 6408 [72, 3.3211541e+04, 1.2182123e+02], 6409 [73, 3.2070576e+04, 1.2305430e+02] 6410 ] 6411 for res_num, value, error in data: 6412 # Get the spin. 6413 spin = return_spin(spin_id=":%s"%res_num) 6414 6415 # Check the values. 6416 self.assertEqual(spin.r2eff['sq_cpmg_800.00000000_0.000_66.667'], value) 6417 self.assertEqual(spin.r2eff_err['sq_cpmg_800.00000000_0.000_66.667'], error)
6418 6419
6420 - def test_r2eff_read_spin(self):
6421 """Test the operation of the relax_disp.r2eff_read_spin user function.""" 6422 6423 # The path to the data files. 6424 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 6425 6426 # Generate the sequence. 6427 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 6428 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 6429 self.interpreter.spin.isotope('1H', spin_id='@H') 6430 self.interpreter.spin.isotope('15N', spin_id='@N') 6431 6432 # Build the experiment IDs. 6433 H_disp_points = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 6434 N_disp_points = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 6435 ids = [] 6436 for value in H_disp_points: 6437 ids.append('1H_CPMG_%s' % value) 6438 for value in N_disp_points: 6439 ids.append('15N_CPMG_%s' % value) 6440 print("\n\nThe experiment IDs are %s." % ids) 6441 6442 # Set up the metadata for the experiments. 6443 for id in ids: 6444 self.interpreter.spectrometer.frequency(id=id, frq=500e6) 6445 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 6446 for value in H_disp_points: 6447 self.interpreter.relax_disp.cpmg_setup(spectrum_id='1H_CPMG_%s' % value, cpmg_frq=value) 6448 for value in N_disp_points: 6449 self.interpreter.relax_disp.cpmg_setup(spectrum_id='15N_CPMG_%s' % value, cpmg_frq=value) 6450 6451 # Loop over the experiments. 6452 for id, file, spin_id in [['1H_CPMG', 'hs_500.res', ':9@H'], ['15N_CPMG', 'ns_500.res', ':9@N']]: 6453 # Try reading the file. 6454 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 6455 6456 # Check the global data. 6457 data = [ 6458 ['cpmg_frqs', {'1H_CPMG_667.0': 667.0, '1H_CPMG_1067.0': 1067.0, '15N_CPMG_350.0': 350.0, '1H_CPMG_933.0': 933.0, '15N_CPMG_50.0': 50.0, '15N_CPMG_100.0': 100.0, '1H_CPMG_400.0': 400.0, '1H_CPMG_533.0': 533.0, '1H_CPMG_800.0': 800.0, '15N_CPMG_900.0': 900.0, '15N_CPMG_150.0': 150.0, '15N_CPMG_800.0': 800.0, '1H_CPMG_267.0': 267.0, '1H_CPMG_2667.0': 2667.0, '15N_CPMG_300.0': 300.0, '1H_CPMG_133.0': 133.0, '15N_CPMG_700.0': 700.0, '1H_CPMG_67.0': 67.0, '15N_CPMG_400.0': 400.0, '15N_CPMG_250.0': 250.0, '1H_CPMG_2133.0': 2133.0, '1H_CPMG_1600.0': 1600.0, '15N_CPMG_200.0': 200.0, '15N_CPMG_1000.0': 1000.0, '15N_CPMG_500.0': 500.0, '15N_CPMG_600.0': 600.0}], 6459 ['cpmg_frqs_list', [50.0, 67.0, 100.0, 133.0, 150.0, 200.0, 250.0, 267.0, 300.0, 350.0, 400.0, 500.0, 533.0, 600.0, 667.0, 700.0, 800.0, 900.0, 933.0, 1000.0, 1067.0, 1600.0, 2133.0, 2667.0]], 6460 ['dispersion_points', 24], 6461 ['exp_type', {'1H_CPMG_667.0': 'SQ CPMG', '1H_CPMG_1067.0': 'SQ CPMG', '15N_CPMG_350.0': 'SQ CPMG', '1H_CPMG_933.0': 'SQ CPMG', '15N_CPMG_50.0': 'SQ CPMG', '15N_CPMG_100.0': 'SQ CPMG', '1H_CPMG_400.0': 'SQ CPMG', '1H_CPMG_533.0': 'SQ CPMG', '1H_CPMG_800.0': 'SQ CPMG', '15N_CPMG_900.0': 'SQ CPMG', '15N_CPMG_150.0': 'SQ CPMG', '15N_CPMG_800.0': 'SQ CPMG', '1H_CPMG_267.0': 'SQ CPMG', '1H_CPMG_2667.0': 'SQ CPMG', '15N_CPMG_300.0': 'SQ CPMG', '1H_CPMG_133.0': 'SQ CPMG', '15N_CPMG_700.0': 'SQ CPMG', '1H_CPMG_67.0': 'SQ CPMG', '15N_CPMG_400.0': 'SQ CPMG', '15N_CPMG_250.0': 'SQ CPMG', '1H_CPMG_2133.0': 'SQ CPMG', '1H_CPMG_1600.0': 'SQ CPMG', '15N_CPMG_200.0': 'SQ CPMG', '15N_CPMG_1000.0': 'SQ CPMG', '15N_CPMG_500.0': 'SQ CPMG', '15N_CPMG_600.0': 'SQ CPMG'}], 6462 ['exp_type_list', ['SQ CPMG']], 6463 ['spectrometer_frq', {'1H_CPMG_667.0': 500000000.0, '1H_CPMG_1067.0': 500000000.0, '15N_CPMG_350.0': 500000000.0, '1H_CPMG_933.0': 500000000.0, '15N_CPMG_50.0': 500000000.0, '15N_CPMG_100.0': 500000000.0, '1H_CPMG_400.0': 500000000.0, '1H_CPMG_533.0': 500000000.0, '1H_CPMG_800.0': 500000000.0, '15N_CPMG_900.0': 500000000.0, '15N_CPMG_150.0': 500000000.0, '15N_CPMG_800.0': 500000000.0, '1H_CPMG_267.0': 500000000.0, '1H_CPMG_2667.0': 500000000.0, '15N_CPMG_300.0': 500000000.0, '1H_CPMG_133.0': 500000000.0, '15N_CPMG_700.0': 500000000.0, '1H_CPMG_67.0': 500000000.0, '15N_CPMG_400.0': 500000000.0, '15N_CPMG_250.0': 500000000.0, '1H_CPMG_2133.0': 500000000.0, '1H_CPMG_1600.0': 500000000.0, '15N_CPMG_200.0': 500000000.0, '15N_CPMG_1000.0': 500000000.0, '15N_CPMG_500.0': 500000000.0, '15N_CPMG_600.0': 500000000.0}], 6464 ['spectrometer_frq_count', 1], 6465 ['spectrometer_frq_list', [500000000.0]], 6466 ['spectrum_ids', ['1H_CPMG_67.0', '1H_CPMG_133.0', '1H_CPMG_267.0', '1H_CPMG_400.0', '1H_CPMG_533.0', '1H_CPMG_667.0', '1H_CPMG_800.0', '1H_CPMG_933.0', '1H_CPMG_1067.0', '1H_CPMG_1600.0', '1H_CPMG_2133.0', '1H_CPMG_2667.0', '15N_CPMG_50.0', '15N_CPMG_100.0', '15N_CPMG_150.0', '15N_CPMG_200.0', '15N_CPMG_250.0', '15N_CPMG_300.0', '15N_CPMG_350.0', '15N_CPMG_400.0', '15N_CPMG_500.0', '15N_CPMG_600.0', '15N_CPMG_700.0', '15N_CPMG_800.0', '15N_CPMG_900.0', '15N_CPMG_1000.0']] 6467 ] 6468 for name, value in data: 6469 # Does it exist? 6470 self.assert_(hasattr(cdp, name)) 6471 6472 # Check the object. 6473 obj = getattr(cdp, name) 6474 if not isinstance(data, dict): 6475 self.assertEqual(obj, value) 6476 6477 # Check the global dictionary data. 6478 else: 6479 for id in ids: 6480 self.assertEqual(obj[id], value[id]) 6481 6482 # Check the spin data. 6483 h_data = [ 6484 [ 67.0, 21.47924, 0.42958], 6485 [ 133.0, 16.73898, 0.33478], 6486 [ 267.0, 9.97357, 0.19947], 6487 [ 400.0, 8.23877, 0.24737], 6488 [ 533.0, 7.59290, 0.24263], 6489 [ 667.0, 7.45843, 0.24165], 6490 [ 800.0, 7.11222, 0.23915], 6491 [ 933.0, 7.40880, 0.24129], 6492 [1067.0, 6.55191, 0.16629], 6493 [1600.0, 6.72177, 0.23637], 6494 [2133.0, 7.09629, 0.23904], 6495 [2667.0, 7.14675, 0.23940] 6496 ] 6497 for disp_point, value, error in h_data: 6498 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 6499 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 6500 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 6501 n_data = [ 6502 [ 50.0, 27.15767, 0.54315], 6503 [ 100.0, 26.55781, 0.53116], 6504 [ 150.0, 24.73462, 0.49469], 6505 [ 200.0, 20.98617, 0.41972], 6506 [ 250.0, 17.82442, 0.35649], 6507 [ 300.0, 15.55352, 0.31107], 6508 [ 350.0, 13.78958, 0.27579], 6509 [ 400.0, 12.48334, 0.24967], 6510 [ 500.0, 11.55724, 0.23114], 6511 [ 600.0, 10.53874, 0.21077], 6512 [ 700.0, 10.07395, 0.20148], 6513 [ 800.0, 9.62952, 0.19259], 6514 [ 900.0, 9.49994, 0.19000], 6515 [1000.0, 8.71350, 0.17427] 6516 ] 6517 for disp_point, value, error in n_data: 6518 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 6519 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff[id], value) 6520 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff_err[id], error)
6521 6522
6523 - def test_r2eff_fit_fixed_time(self):
6524 """Test the relaxation dispersion 'R2eff' model for fixed time data in the auto-analysis.""" 6525 6526 # Execute the script. 6527 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r2eff_calc.py')
6528 6529
6530 - def test_read_r2eff(self):
6531 """Test the reading of a file containing r2eff values.""" 6532 6533 # Create the sequence data, and name the spins. 6534 self.interpreter.residue.create(1, 'Gly') 6535 self.interpreter.residue.create(2, 'Gly') 6536 self.interpreter.residue.create(3, 'Gly') 6537 6538 # Read the file. 6539 self.interpreter.relax_data.read(ri_id='R2eff.600', ri_type='R2eff', frq=600*1e6, file='r2eff.out', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r2eff', res_num_col=1, res_name_col=2, data_col=3, error_col=4) 6540 6541 # Test the data. 6542 self.assertEqual(cdp.mol[0].res[0].spin[0].ri_data['R2eff.600'], 15.000) 6543 self.assertEqual(cdp.mol[0].res[1].spin[0].ri_data['R2eff.600'], 4.2003) 6544 self.assertEqual(cdp.mol[0].res[2].spin[0].ri_data['R2eff.600'], 7.2385)
6545 6546
6548 """Test speeding up grid search. Support requst sr #3151 U{https://gna.org/support/index.php?3151}. 6549 6550 User function to set the R20 parameters in the default grid search using the minimum R2eff value. 6551 6552 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 6553 'SOD1-WT' CPMG data to the CR72 dispersion model. 6554 6555 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 6556 Data is for experiment at 25 degree Celcius. 6557 """ 6558 6559 # Base data setup. 6560 pipe_name = 'base pipe' 6561 pipe_type = 'relax_disp' 6562 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 6563 select_spin_index = list(range(0, 1)) 6564 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 6565 6566 # Generate r20 key. 6567 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 6568 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 6569 6570 ## Now prepare for MODEL calculation. 6571 MODEL = "CR72" 6572 6573 # Change pipe. 6574 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 6575 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 6576 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 6577 6578 # Then select model. 6579 self.interpreter.relax_disp.select_model(model=MODEL) 6580 6581 # Set the R20 parameters in the default grid search using the minimum R2eff value. 6582 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 6583 6584 # Test result, for normal run. 6585 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6586 # Get the spin_params. 6587 spin_params = spin.params 6588 6589 # Defined fixed values for testing. 6590 if spin_id == ":10@N": 6591 self.assertEqual(spin.r2[r20_key_600], 20.282732526087106) 6592 self.assertEqual(spin.r2[r20_key_500], 18.475299724356649) 6593 6594 # Print out. 6595 print("r2_600=%2.2f r2_500=%2.2f spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin_id, resi, resn)) 6596 6597 # Testing the r2 values for the different fields are not the same. 6598 self.assert_(spin.r2[r20_key_600] != spin.r2[r20_key_500]) 6599 6600 # Test values are larger than 0. 6601 self.assert_(spin.r2[r20_key_600] > 0.0) 6602 self.assert_(spin.r2[r20_key_500] > 0.0) 6603 6604 # Loop over the experiment settings. 6605 r2eff_600 = [] 6606 r2eff_500 = [] 6607 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 6608 # Create the data key. 6609 data_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 6610 6611 # Extract the r2 eff data. 6612 r2eff = spin.r2eff[data_key] 6613 if frq == 599.8908617*1E6: 6614 r2eff_600.append(r2eff) 6615 elif frq == 499.862139*1E6: 6616 r2eff_500.append(r2eff) 6617 6618 # Sort values. 6619 r2eff_600.sort() 6620 r2eff_500.sort() 6621 6622 # Test values again. 6623 print("For r20 600MHz min r2eff=%3.3f."%(min(r2eff_600))) 6624 print(r2eff_600) 6625 self.assertEqual(spin.r2[r20_key_600], min(r2eff_600)) 6626 print("") 6627 6628 print("For r20 500MHz min r2eff=%3.3f."%(min(r2eff_500))) 6629 print(r2eff_500) 6630 self.assertEqual(spin.r2[r20_key_500], min(r2eff_500)) 6631 print("") 6632 6633 print("###########################################") 6634 print("Trying GRID SEARCH for minimum R2eff values") 6635 6636 ### Test just the Grid search. 6637 GRID_INC = 5 6638 6639 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 6640 6641 ### Then test the value.set function. 6642 # Change pipe. 6643 pipe_name_MODEL = "%s_%s_2"%(pipe_name, MODEL) 6644 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 6645 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 6646 6647 # Then select model. 6648 self.interpreter.relax_disp.select_model(model=MODEL) 6649 6650 # Then set the standard parameter values. 6651 for param in spin_params: 6652 print("Setting standard parameter for param: %s"%param) 6653 self.interpreter.value.set(param=param, index=None) 6654 6655 # Test result, for normal run. 6656 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6657 # Print out. 6658 print("r2_600=%2.2f r2_500=%2.2f pA=%2.2f, dw=%2.2f, kex=%2.2f, spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin.pA, spin.dw, spin.kex, spin_id, resi, resn)) 6659 6660 # Testing the r2 values. 6661 self.assertEqual(spin.r2[r20_key_600], 10.00) 6662 self.assertEqual(spin.r2[r20_key_500], 10.00) 6663 self.assertEqual(spin.pA, 0.9) 6664 self.assertEqual(spin.dw, 1.0) 6665 self.assertEqual(spin.kex, 1000.0) 6666 6667 print("###########################################") 6668 print("Trying GRID SEARCH for standard R2eff values") 6669 6670 ### Test just the Grid search. 6671 GRID_INC = 5 6672 6673 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 6674 6675 ### Run auto_analysis. 6676 # The grid search size (the number of increments per dimension). 6677 GRID_INC = 5 6678 6679 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6680 MC_NUM = 3 6681 6682 # Model selection technique. 6683 MODSEL = 'AIC' 6684 6685 # Execute the auto-analysis (fast). 6686 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6687 OPT_FUNC_TOL = 1e-1 6688 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6689 OPT_MAX_ITERATIONS = 1000 6690 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6691 6692 # Run the analysis. 6693 relax_disp.Relax_disp(pipe_name=pipe_name_r2eff, results_dir=ds.tmpdir, models=[MODEL], grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, set_grid_r20=True)
6694 6695
6697 """Error analysis of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 6698 6699 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 6700 'SOD1-WT' CPMG data to the CR72 dispersion model. 6701 6702 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 6703 Data is for experiment at 25 degree Celcius. 6704 6705 bug #21954 U{https://gna.org/bugs/index.php?21954}: Order of spectrum.error_analysis is important. 6706 """ 6707 6708 # Base data setup. 6709 pipe_name = 'base pipe' 6710 pipe_type = 'relax_disp' 6711 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 6712 select_spin_index = list(range(0, 1)) 6713 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 6714 6715 # Define replicated 6716 repl_A = ['Z_A1', 'Z_A15'] 6717 repl_B = ['Z_B1', 'Z_B18'] 6718 6719 # Loop over spectrum ID, and sort them 6720 spectrum_ids_A = [] 6721 spectrum_ids_B = [] 6722 for spectrum_id in cdp.spectrum_ids: 6723 if "A" in spectrum_id: 6724 spectrum_ids_A.append(spectrum_id) 6725 elif "B" in spectrum_id: 6726 spectrum_ids_B.append(spectrum_id) 6727 6728 # To clean up old error analysis, delete attributes 6729 delattr(cdp, "var_I") 6730 delattr(cdp, "sigma_I") 6731 6732 # Perform error analysis 6733 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 6734 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 6735 6736 # Loop over spins, save errors to list 6737 Errors_A_B = [] 6738 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6739 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 6740 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 6741 Errors_A_B.append([A_err, B_err]) 6742 6743 # To clean up old error analysis, delete attributes 6744 delattr(cdp, "var_I") 6745 delattr(cdp, "sigma_I") 6746 6747 # Perform error analysis. Order is important 6748 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 6749 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 6750 6751 # Loop over spins, save errors to list 6752 Errors_B_A = [] 6753 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6754 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 6755 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 6756 Errors_B_A.append([A_err, B_err]) 6757 6758 # Make test for order of error 6759 for i in range(len(Errors_A_B)): 6760 Error_A_B = Errors_A_B[i] 6761 Error_B_A = Errors_B_A[i] 6762 self.assertAlmostEqual(Error_A_B[0], Error_B_A[0], 4) 6763 self.assertAlmostEqual(Error_A_B[1], Error_B_A[1], 4) 6764 6765 # Make further tests for fixed values 6766 std_A = math.sqrt((cdp.var_I[repl_A[0]] + cdp.var_I[repl_A[1]])/2) 6767 std_A_fix = 2785.7263335738567 6768 6769 for id_A in spectrum_ids_A: 6770 self.assertEqual(cdp.sigma_I[id_A], std_A) 6771 self.assertAlmostEqual(cdp.sigma_I[id_A], std_A_fix, 7) 6772 6773 std_B = math.sqrt((cdp.var_I[repl_B[0]] + cdp.var_I[repl_B[1]])/2) 6774 std_B_fix = 4967.3772030667988 6775 6776 for id_B in spectrum_ids_B: 6777 self.assertEqual(cdp.sigma_I[id_B], std_B) 6778 self.assertAlmostEqual(cdp.sigma_I[id_B], std_B_fix, 7)
6779 6780
6781 - def test_sod1wt_t25_to_cr72(self):
6782 """Optimisation of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 6783 6784 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 6785 'SOD1-WT' CPMG data to the CR72 dispersion model. 6786 6787 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 6788 Data is for experiment at 25 degree Celcius. 6789 """ 6790 6791 # Base data setup. 6792 pipe_name = 'base pipe' 6793 pipe_type = 'relax_disp' 6794 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 6795 select_spin_index = list(range(0, 2)) 6796 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 6797 6798 # Generate r20 key. 6799 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 6800 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 6801 6802 ## Now prepare for MODEL calculation. 6803 MODEL = "CR72" 6804 6805 # Change pipe. 6806 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 6807 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 6808 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 6809 6810 # Then select model. 6811 self.interpreter.relax_disp.select_model(model=MODEL) 6812 6813 # GRID inc of 7 was found to be appropriate not to find pA = 0.5. 6814 GRID_INC = 7 6815 6816 # Store grid and minimisations results. 6817 grid_results = [] 6818 mini_results = [] 6819 clust_results = [] 6820 6821 # Set the R20 parameters in the default grid search using the minimum R2eff value. 6822 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 6823 6824 # Deselect insignificant spins. 6825 self.interpreter.relax_disp.insignificance(level=1.0) 6826 6827 # Perform Grid Search. 6828 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 6829 6830 # Store result. 6831 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6832 # Store grid results. 6833 grid_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 6834 6835 ## Now do minimisation. 6836 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6837 set_func_tol = 1e-9 6838 set_max_iter = 100000 6839 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 6840 6841 # Store result. 6842 pA_values = [] 6843 kex_values = [] 6844 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6845 # Store minimisation results. 6846 mini_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 6847 6848 # Store pA values. 6849 pA_values.append(spin.pA) 6850 6851 # Store kex values. 6852 kex_values.append(spin.kex) 6853 6854 print("\n# Now print before and after minimisation.\n") 6855 6856 # Print results. 6857 for i in range(len(grid_results)): 6858 # Get values. 6859 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 6860 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 6861 6862 print("GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 6863 print("MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 6864 6865 ## Prepare for clustering 6866 # Change pipe. 6867 pipe_name_MODEL_CLUSTER = "%s_%s_Cluster"%(pipe_name, MODEL) 6868 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL_CLUSTER) 6869 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL_CLUSTER) 6870 6871 # Then select model. 6872 self.interpreter.relax_disp.select_model(model=MODEL) 6873 6874 # Define cluster id. 6875 cluster_id = 'clust' 6876 6877 # Loop over spins to cluster them. 6878 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6879 self.interpreter.relax_disp.cluster(cluster_id, spin_id) 6880 6881 # Copy over values. 6882 self.interpreter.relax_disp.parameter_copy(pipe_from=pipe_name_MODEL, pipe_to=pipe_name_MODEL_CLUSTER) 6883 6884 # Test the median values is correct 6885 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6886 print(pA_values) 6887 # The the median pA value returned. 6888 self.assertEqual(median(pA_values), spin.pA) 6889 6890 # The the median kex value returned. 6891 self.assertEqual(median(kex_values), spin.kex) 6892 6893 ## Now do minimisation. 6894 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 6895 6896 # Store result. 6897 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6898 # Store clust results. 6899 clust_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 6900 6901 # Store the outcome of the clustering minimisation. 6902 clust_pA = spin.pA 6903 clust_kex = spin.kex 6904 6905 print("\n# Now testing.\n") 6906 6907 # Define results 6908 test_res = {} 6909 test_res[':10@N'] = {} 6910 test_res[':10@N']['r2600'] = 18.429755324773360 6911 test_res[':10@N']['r2500'] = 16.981349161968630 6912 test_res[':10@N']['dw'] = 2.700755859433969 6913 test_res[':10@N']['pA'] = 0.971531659288657 6914 test_res[':10@N']['kex'] = 3831.766337047963134 6915 test_res[':11@N'] = {} 6916 test_res[':11@N']['r2600'] = 18.193409421115213 6917 test_res[':11@N']['r2500'] = 17.308838135567765 6918 test_res[':11@N']['dw'] = 2.706650302761793 6919 test_res[':11@N']['pA'] = 0.971531659288657 6920 test_res[':11@N']['kex'] = 3831.766337047963134 6921 6922 # Then make tests. 6923 for i in range(len(grid_results)): 6924 # Get values. 6925 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 6926 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 6927 c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn = clust_results[i] 6928 6929 print("%s GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 6930 print("%s MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 6931 print("%s Clust r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn)) 6932 6933 # Make tests. 6934 self.assertEqual(clust_pA, c_pA) 6935 self.assertEqual(clust_kex, c_kex) 6936 6937 # Test values. 6938 if c_spin_id in test_res: 6939 self.assertAlmostEqual(c_r2_600, test_res[c_spin_id]['r2600'], 4) 6940 self.assertAlmostEqual(c_r2_500, test_res[c_spin_id]['r2500'], 4) 6941 self.assertAlmostEqual(c_dw, test_res[c_spin_id]['dw'], 3) 6942 self.assertAlmostEqual(c_pA, test_res[c_spin_id]['pA'], 5) 6943 self.assertAlmostEqual(c_kex, test_res[c_spin_id]['kex'], 1)
6944 6945 # Save disp graph to temp. 6946 #self.interpreter.relax_disp.plot_disp_curves(dir="~"+sep+"test", num_points=1000, extend=500.0, force=True). 6947 6948
6950 """Conversion of SOD1-WT CPMG R2eff values into input files for sherekhan. 6951 6952 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 6953 'SOD1-WT' CPMG data to the CR72 dispersion model. 6954 6955 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 6956 Data is for experiment at 25 degree Celcius. 6957 """ 6958 6959 # Base data setup. 6960 pipe_name = 'base pipe' 6961 pipe_type = 'relax_disp' 6962 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 6963 select_spin_index = list(range(0, 2)) 6964 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 6965 6966 # Generate r20 key. 6967 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 6968 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 6969 6970 # Cluster everything, to analyse together. 6971 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-1000") 6972 6973 # Write input 6974 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=ds.tmpdir) 6975 6976 # Check the r2eff set files. 6977 print("\nChecking the R2eff input set files.") 6978 files = [[ds.tmpdir + sep + 'cluster1', 'sherekhan_frq1.in'], [ ds.tmpdir + sep + 'cluster1', 'sherekhan_frq2.in']] 6979 6980 # First check file exists 6981 for dir, file in files: 6982 print(dir+sep+file) 6983 self.assert_(access(dir+sep+file, F_OK)) 6984 6985 # Define how files should look like 6986 data_set_600 = [ 6987 "60.8272464287\n", 6988 "0.06\n", 6989 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 6990 "# G10\n", 6991 " 33.333 26.53556078711 0.5236104771163\n", 6992 " 66.667 25.29735243318 0.48766574122\n", 6993 " 100 25.09470361403 0.4820438864671\n", 6994 " 133.333 25.15603274331 0.4837377286085\n", 6995 " 166.667 24.27213341753 0.4599457904395\n", 6996 " 200 24.00364120328 0.4529773198905\n", 6997 " 266.667 24.03511395168 0.4537880662536\n", 6998 " 300 23.04761040024 0.4291039120557\n", 6999 " 333.333 22.95530300787 0.4268745963972\n", 7000 " 400 23.06158810662 0.4294426293624\n", 7001 " 466.667 22.26799054092 0.4106809618644\n", 7002 " 533.333 21.99851418823 0.4045232104735\n", 7003 " 666.667 21.19651570955 0.3868136173831\n", 7004 " 833.333 20.30938498379 0.3682604887899\n", 7005 " 1000 20.28273252609 0.367719392568\n", 7006 "# D11\n", 7007 " 33.333 24.76520269878 0.5026475808706\n", 7008 " 66.667 24.8773107448 0.5058752916906\n", 7009 " 100 24.90357815239 0.5066348551479\n", 7010 " 133.333 23.7782506151 0.4751950583865\n", 7011 " 166.667 23.68548762076 0.4727017128631\n", 7012 " 200 23.58629651618 0.4700517377679\n", 7013 " 266.667 23.47734671187 0.4671601744044\n", 7014 " 300 24.08647493772 0.4835855560598\n", 7015 " 333.333 22.98314371029 0.4542918950801\n", 7016 " 400 22.80339361568 0.4497107885587\n", 7017 " 466.667 22.91634335366 0.4525833037874\n", 7018 " 533.333 22.59774140046 0.4445334311324\n", 7019 " 666.667 20.9177750759 0.4046955726046\n", 7020 " 833.333 20.71792550566 0.4002363835007\n", 7021 " 1000 19.54080006349 0.3751112751853\n", 7022 ] 7023 7024 # Check data_set_600 7025 file = open(files[0][0]+sep+files[0][1]) 7026 lines = file.readlines() 7027 file.close() 7028 self.assertEqual(len(data_set_600), len(lines)) 7029 for i in range(len(data_set_600)): 7030 # Make the string test 7031 self.assertEqual(data_set_600[i], lines[i]) 7032 7033 # Define how files should look like 7034 data_set_500 = [ 7035 "50.6846152368\n", 7036 "0.04\n", 7037 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 7038 "# G10\n", 7039 " 50 22.28084307393 0.2944966344183\n", 7040 " 100 21.93494977761 0.2910362768307\n", 7041 " 150 21.09850032232 0.282892238351\n", 7042 " 200 20.86493960397 0.2806737853646\n", 7043 " 250 20.75287269752 0.2796178205016\n", 7044 " 300 20.25597152406 0.2750013546989\n", 7045 " 350 19.92172163467 0.2719555756504\n", 7046 " 400 19.97712052922 0.272457105051\n", 7047 " 450 19.46807010415 0.2678972122793\n", 7048 " 500 19.76875460947 0.2705774849203\n", 7049 " 550 19.39161367402 0.2672216964327\n", 7050 " 600 19.03949517697 0.2641417899694\n", 7051 " 650 19.12218812132 0.2648605059901\n", 7052 " 700 19.01037461457 0.2638893584683\n", 7053 " 800 18.83395162904 0.2623674321143\n", 7054 " 900 18.47529972436 0.2593123604687\n", 7055 " 1000 18.5252023121 0.2597343394038\n", 7056 "# D11\n", 7057 " 50 22.15403890237 0.3285588379827\n", 7058 " 100 21.80946781746 0.3247185598713\n", 7059 " 150 21.77715415505 0.324361526682\n", 7060 " 200 21.41647464235 0.3204122024881\n", 7061 " 250 21.17099940822 0.3177616325958\n", 7062 " 300 21.03740030577 0.3163316496664\n", 7063 " 350 20.95393648281 0.3154427665172\n", 7064 " 400 20.93311399332 0.315221543436\n", 7065 " 450 20.18219905222 0.3073848655291\n", 7066 " 500 19.93599065085 0.3048744697057\n", 7067 " 550 19.68475725452 0.3023424499113\n", 7068 " 600 19.33575433934 0.2988741928798\n", 7069 " 650 19.53915692194 0.3008886196853\n", 7070 " 700 19.2018754351 0.2975587767134\n", 7071 " 800 18.82360965368 0.2938866923878\n", 7072 " 900 18.71861761238 0.2928790380131\n", 7073 " 1000 17.95878049287 0.2857341721151\n", 7074 ] 7075 7076 # Check data_set_500 7077 file = open(files[1][0]+sep+files[1][1]) 7078 lines = file.readlines() 7079 file.close() 7080 self.assertEqual(len(data_set_500), len(lines)) 7081 for i in range(len(data_set_500)): 7082 # Make the string test 7083 self.assertEqual(data_set_500[i], lines[i]) 7084 7085 # Test local dir tests. This will be turned off in system test. 7086 turn_on_local_dir_test = False 7087 7088 if turn_on_local_dir_test: 7089 ## Now check to local folder with None argument. 7090 # Write input 7091 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None) 7092 7093 # Check the r2eff set files. 7094 print("\nChecking the R2eff input set files.") 7095 files = [[path.join(getcwd(), 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), 'cluster1'), 'sherekhan_frq2.in']] 7096 7097 # First check file exists 7098 for dir, file in files: 7099 print(dir+sep+file) 7100 self.assert_(access(dir+sep+file, F_OK)) 7101 7102 ## Now check to local folder with dir argument. 7103 # Write input 7104 set_dir = "Test_ShereKhan" 7105 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=set_dir) 7106 7107 # Check the r2eff set files. 7108 print("\nChecking the R2eff input set files.") 7109 files = [[path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq2.in']] 7110 7111 # First check file exists 7112 for dir, file in files: 7113 print(dir+sep+file) 7114 self.assert_(access(dir+sep+file, F_OK))
7115 7116
7117 - def test_sprangers_data_to_mmq_cr72(self, model=None):
7118 """Test the 'MMQ CR72' model fitting against Remco Sprangers' ClpP data. 7119 7120 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MMQ CPMG data with a fixed relaxation time period. 7121 """ 7122 7123 # Reset. 7124 self.interpreter.reset() 7125 7126 # Create the data pipe and load the base data. 7127 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 7128 self.interpreter.state.load(data_path+sep+'r2eff_values') 7129 7130 # The model data pipe. 7131 model = 'MMQ CR72' 7132 pipe_name = "%s - relax_disp" % model 7133 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 7134 self.interpreter.pipe.switch(pipe_name=pipe_name) 7135 7136 # Set the model. 7137 self.interpreter.relax_disp.select_model(model=model) 7138 7139 # Cluster everything. 7140 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 7141 7142 # Copy the data. 7143 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 7144 7145 # Alias the spins. 7146 spin135S = cdp.mol[0].res[0].spin[0] 7147 spin135F = cdp.mol[0].res[0].spin[1] 7148 spin137S = cdp.mol[0].res[1].spin[0] 7149 spin137F = cdp.mol[0].res[1].spin[1] 7150 7151 # The R20 keys. 7152 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 7153 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 7154 7155 # Set the cluster specific parameters (only for the first spin). 7156 spin135S.pA = 0.836591763632 7157 spin135S.kex = 241.806525261 7158 7159 # Set the initial parameter values. 7160 spin135S.r2 = {r20_key1: 28.2493431552, r20_key2: 31.7517334715} 7161 spin135S.dw = 0.583003118785 7162 spin135S.dwH = 0.0361441944301 7163 7164 spin135F.r2 = {r20_key1: 42.7201839991, r20_key2: 57.3178617389} 7165 spin135F.dw = 0.805849745104 7166 spin135F.dwH = 0.0215791945715 7167 7168 spin137S.r2 = {r20_key1: 26.0134115256, r20_key2: 30.575806934} 7169 spin137S.dw = 0.688107568372 7170 spin137S.dwH = 0.0344463604043 7171 7172 spin137F.r2 = {r20_key1: 46.6969397337, r20_key2: 58.602384101} 7173 spin137F.dw = 0.94978299907 7174 spin137F.dwH = 1.4818877939e-07 7175 7176 # Low precision optimisation. 7177 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-10, max_iter=1000) 7178 7179 # Printout. 7180 print("\n\nOptimised parameters:\n") 7181 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 7182 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 7183 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 7184 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 7185 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 7186 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 7187 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 7188 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 7189 print("\n # Set the cluster specific parameters (only for the first spin).") 7190 print(" spin135S.pA = %s" % spin135S.pA) 7191 print(" spin135S.kex = %s" % spin135S.kex) 7192 print("\n # Set the initial parameter values.") 7193 print(" spin135S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135S.r2[r20_key1], spin135S.r2[r20_key2])) 7194 print(" spin135S.dw = %s" % spin135S.dw) 7195 print(" spin135S.dwH = %s" % spin135S.dwH) 7196 print("\n spin135F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135F.r2[r20_key1], spin135F.r2[r20_key2])) 7197 print(" spin135F.dw = %s" % spin135F.dw) 7198 print(" spin135F.dwH = %s" % spin135F.dwH) 7199 print("\n spin137S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137S.r2[r20_key1], spin137S.r2[r20_key2])) 7200 print(" spin137S.dw = %s" % spin137S.dw) 7201 print(" spin137S.dwH = %s" % spin137S.dwH) 7202 print("\n spin137F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137F.r2[r20_key1], spin137F.r2[r20_key2])) 7203 print(" spin137F.dw = %s" % spin137F.dw) 7204 print(" spin137F.dwH = %s" % spin137F.dwH) 7205 7206 # Checks for residue :135S. 7207 self.assertAlmostEqual(spin135S.r2[r20_key1], 28.2493445347425, 4) 7208 self.assertAlmostEqual(spin135S.r2[r20_key2], 31.7517352342937, 4) 7209 self.assertAlmostEqual(spin135S.pA, 0.836591714049569, 4) 7210 self.assertAlmostEqual(spin135S.dw, 0.583003004605869, 4) 7211 self.assertAlmostEqual(spin135S.dwH, 0.0361441894065963, 4) 7212 self.assertAlmostEqual(spin135S.kex/100, 241.806464344233/100, 4) 7213 self.assertAlmostEqual(spin135S.chi2, 12.4224060116473, 4) 7214 7215 # Checks for residue :135F. 7216 self.assertAlmostEqual(spin135F.r2[r20_key1], 42.7201844426839, 4) 7217 self.assertAlmostEqual(spin135F.r2[r20_key2], 57.3178718548898, 4) 7218 self.assertAlmostEqual(spin135F.pA, 0.836591714049569, 4) 7219 self.assertAlmostEqual(spin135F.dw, 0.805849748711916, 4) 7220 self.assertAlmostEqual(spin135F.dwH, 0.0215791669142752, 4) 7221 self.assertAlmostEqual(spin135F.kex/100, 241.806464344233/100, 4) 7222 self.assertAlmostEqual(spin135F.chi2, 12.4224060116473, 4) 7223 7224 # Checks for residue :137S. 7225 self.assertAlmostEqual(spin137S.r2[r20_key1], 26.013412509919, 4) 7226 self.assertAlmostEqual(spin137S.r2[r20_key2], 30.5758092335097, 4) 7227 self.assertAlmostEqual(spin137S.pA, 0.836591714049569, 4) 7228 self.assertAlmostEqual(spin137S.dw, 0.688107406812537, 4) 7229 self.assertAlmostEqual(spin137S.dwH, 0.034446357344577, 4) 7230 self.assertAlmostEqual(spin137S.kex/100, 241.806464344233/100, 4) 7231 self.assertAlmostEqual(spin137S.chi2, 12.4224060116473, 4) 7232 7233 # Checks for residue :137F. 7234 self.assertAlmostEqual(spin137F.r2[r20_key1], 46.696935090697, 4) 7235 self.assertAlmostEqual(spin137F.r2[r20_key2], 58.6023842513446, 4) 7236 self.assertAlmostEqual(spin137F.pA, 0.836591714049569, 4) 7237 self.assertAlmostEqual(spin137F.dw, 0.94978325541294, 4) 7238 self.assertAlmostEqual(spin137F.dwH, 1.5189362257653e-07, 4) 7239 self.assertAlmostEqual(spin137F.kex/100, 241.806464344233/100, 4) 7240 self.assertAlmostEqual(spin137F.chi2, 12.4224060116473, 4)
7241 7242
7243 - def test_sprangers_data_to_ns_mmq_2site(self, model=None):
7244 """Test the 'NS MMQ 2-site' model fitting against Remco Sprangers' ClpP data. 7245 7246 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MQ CPMG data with a fixed relaxation time period. 7247 """ 7248 7249 # Reset. 7250 self.interpreter.reset() 7251 7252 # Create the data pipe and load the base data. 7253 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 7254 self.interpreter.state.load(data_path+sep+'r2eff_values') 7255 7256 # The model data pipe. 7257 model = 'NS MMQ 2-site' 7258 pipe_name = "%s - relax_disp" % model 7259 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 7260 self.interpreter.pipe.switch(pipe_name=pipe_name) 7261 7262 # Set the model. 7263 self.interpreter.relax_disp.select_model(model=model) 7264 7265 # Cluster everything. 7266 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 7267 7268 # Copy the data. 7269 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 7270 7271 # Alias the spins. 7272 spin135S = cdp.mol[0].res[0].spin[0] 7273 spin135F = cdp.mol[0].res[0].spin[1] 7274 spin137S = cdp.mol[0].res[1].spin[0] 7275 spin137F = cdp.mol[0].res[1].spin[1] 7276 7277 # The R20 keys. 7278 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 7279 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 7280 7281 # Set the cluster specific parameters (only for the first spin). 7282 spin135S.pA = 0.847378444499757 7283 spin135S.kex = 264.055604934724329 7284 7285 # Set the initial parameter values. 7286 spin135S.r2 = {r20_key1: 30.315119723745390, r20_key2: 37.411874745645299} 7287 spin135S.dw = 0.585574008745351 7288 spin135S.dwH = 0.000000000000002 7289 7290 spin135F.r2 = {r20_key1: 41.440843383778287, r20_key2: 56.989726795397893} 7291 spin135F.dw = 0.856699277665748 7292 spin135F.dwH = 0.000000000582587 7293 7294 spin137S.r2 = {r20_key1: 23.051695938570266, r20_key2: 28.352806483953824} 7295 spin137S.dw = 0.772904450844973 7296 spin137S.dwH = 0.183351478512970 7297 7298 spin137F.r2 = {r20_key1: 44.702032074210429, r20_key2: 56.453146052685319} 7299 spin137F.dw = 0.984568590342831 7300 spin137F.dwH = 0.000000001993458 7301 7302 # Low precision optimisation. 7303 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-5, grad_tol=None, max_iter=100, constraints=True, scaling=True, verbosity=1) 7304 7305 # Printout. 7306 print("\n\nOptimised parameters:\n") 7307 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 7308 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 7309 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 7310 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 7311 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 7312 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 7313 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 7314 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 7315 7316 # FIXME: Remove this temporary return and properly check the results. 7317 return 7318 7319 # Checks for residue :135S. 7320 self.assertAlmostEqual(spin135S.r2[r20_key1], 30.3151197237454, 4) 7321 self.assertAlmostEqual(spin135S.r2[r20_key2], 37.4118747456453, 4) 7322 self.assertAlmostEqual(spin135S.pA, 0.847378444499757, 4) 7323 self.assertAlmostEqual(spin135S.dw, 0.585574008745351, 4) 7324 self.assertAlmostEqual(spin135S.dwH, 2e-15, 4) 7325 self.assertAlmostEqual(spin135S.kex, 264.055604934724, 4) 7326 self.assertAlmostEqual(spin135S.chi2, 13.859423588071, 1) 7327 7328 # Checks for residue :135F. 7329 self.assertAlmostEqual(spin135F.r2[r20_key1], 41.4408433837783, 4) 7330 self.assertAlmostEqual(spin135F.r2[r20_key2], 56.9897267953979, 4) 7331 self.assertAlmostEqual(spin135F.pA, 0.847378444499757, 4) 7332 self.assertAlmostEqual(spin135F.dw, 0.856699277665748, 4) 7333 self.assertAlmostEqual(spin135F.dwH, 5.82587e-10, 4) 7334 self.assertAlmostEqual(spin135F.kex, 264.055604934724, 4) 7335 self.assertAlmostEqual(spin135F.chi2, 13.859423588071, 1) 7336 7337 # Checks for residue :137S. 7338 self.assertAlmostEqual(spin137S.r2[r20_key1], 23.0516959385703, 4) 7339 self.assertAlmostEqual(spin137S.r2[r20_key2], 28.3528064839538, 4) 7340 self.assertAlmostEqual(spin137S.pA, 0.847378444499757, 4) 7341 self.assertAlmostEqual(spin137S.dw, 0.772904450844973, 4) 7342 self.assertAlmostEqual(spin137S.dwH, 0.18335147851297, 4) 7343 self.assertAlmostEqual(spin137S.kex, 264.055604934724, 4) 7344 self.assertAlmostEqual(spin137S.chi2, 13.859423588071, 1) 7345 7346 # Checks for residue :137F. 7347 self.assertAlmostEqual(spin137F.r2[r20_key1], 44.7020320742104, 4) 7348 self.assertAlmostEqual(spin137F.r2[r20_key2], 56.4531460526853, 4) 7349 self.assertAlmostEqual(spin137F.pA, 0.847378444499757, 4) 7350 self.assertAlmostEqual(spin137F.dw, 0.984568590342831, 4) 7351 self.assertAlmostEqual(spin137F.dwH, 2.0931309e-09, 4) 7352 self.assertAlmostEqual(spin137F.kex, 264.055604934724, 4) 7353 self.assertAlmostEqual(spin137F.chi2, 13.859423588071, 1)
7354 7355
7356 - def test_tp02_data_to_ns_r1rho_2site(self, model=None):
7357 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 7358 7359 # Setup the data. 7360 self.setup_tp02_data_to_ns_r1rho_2site() 7361 7362 # Alias the spins. 7363 spin1 = cdp.mol[0].res[0].spin[0] 7364 spin2 = cdp.mol[0].res[1].spin[0] 7365 7366 # The R20 keys. 7367 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 7368 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 7369 7370 # Checks for residue :1. 7371 self.assertAlmostEqual(spin1.r2[r20_key1], 8.50207717367548, 4) 7372 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4680429589972, 4) 7373 self.assertAlmostEqual(spin1.pA, 0.864523128842393, 4) 7374 self.assertAlmostEqual(spin1.dw, 8.85204828994151, 4) 7375 self.assertAlmostEqual(spin1.kex/1000, 1199.56359549637/1000, 4) 7376 self.assertAlmostEqual(spin1.chi2, 2.99182130153514, 4) 7377 7378 # Checks for residue :2. 7379 self.assertAlmostEqual(spin2.r2[r20_key1], 10.2099357790203, 4) 7380 self.assertAlmostEqual(spin2.r2[r20_key2], 16.2137648697873, 4) 7381 self.assertAlmostEqual(spin2.pA, 0.836488681031685, 4) 7382 self.assertAlmostEqual(spin2.dw, 9.5505714779503, 4) 7383 self.assertAlmostEqual(spin2.kex/1000, 1454.45726998929/1000, 4) 7384 self.assertAlmostEqual(spin2.chi2, 0.000402231563481261, 4)
7385 7386
7387 - def test_tp02_data_to_ns_r1rho_2site_cluster(self, model=None):
7388 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data, when performing clustering.""" 7389 7390 # Setup the data. 7391 self.setup_tp02_data_to_ns_r1rho_2site(clustering=True) 7392 7393 # Alias the spins. 7394 spin1 = cdp.mol[0].res[0].spin[0] 7395 spin2 = cdp.mol[0].res[1].spin[0] 7396 7397 # The R20 keys. 7398 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 7399 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 7400 7401 # Checks for residue :1. 7402 self.assertAlmostEqual(spin1.r2[r20_key1], 8.48607207881462, 4) 7403 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4527609061722, 4) 7404 self.assertAlmostEqual(spin1.pA, 0.863093838784425, 4) 7405 self.assertAlmostEqual(spin1.dw, 8.86218096536618, 4) 7406 self.assertAlmostEqual(spin1.kex/1000, 1186.22749648299/1000, 4) 7407 self.assertAlmostEqual(spin1.chi2, 3.09500996065247, 4) 7408 7409 # Checks for residue :2. 7410 self.assertAlmostEqual(spin2.r2[r20_key1], 10.4577906018883, 4) 7411 self.assertAlmostEqual(spin2.r2[r20_key2], 16.4455550953792, 4) 7412 self.assertAlmostEqual(spin2.pA, 0.863093838784425, 4) 7413 self.assertAlmostEqual(spin2.dw, 11.5841168862587, 4) 7414 self.assertAlmostEqual(spin2.kex/1000, 1186.22749648299/1000, 4) 7415 self.assertAlmostEqual(spin2.chi2, 3.09500996065247, 4)
7416 7417
7418 - def test_tp02_data_to_mp05(self):
7419 """Test the dispersion 'MP05' model fitting against the 'TP02' test data.""" 7420 7421 # Fixed time variable and the models. 7422 ds.fixed = True 7423 ds.models = ['R2eff', 'MP05'] 7424 7425 # Execute the script. 7426 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 7427 7428 # Switch back to the data pipe for the optimisation. 7429 self.interpreter.pipe.switch('MP05 - relax_disp') 7430 7431 # The equivalent MP05 parameters. 7432 r1rho_prime = [[10.0058086343329, 15.005806870124], [12.0766320470785, 18.0767503536277]] 7433 pA = [0.775055484521586, 0.500000000036595] 7434 kex = [1235.20361276079, 2378.31403454691] 7435 delta_omega = [7.08194146569694, 5.4083562844306] 7436 chi2 = [0.0370400968727768, 0.182141732163934] 7437 7438 # Alias the spins. 7439 spin1 = cdp.mol[0].res[0].spin[0] 7440 spin2 = cdp.mol[0].res[1].spin[0] 7441 7442 # The R20 keys. 7443 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 7444 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 7445 7446 # Printout. 7447 print("\n\nOptimised parameters:\n") 7448 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 7449 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 7450 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 7451 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 7452 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 7453 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 7454 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 7455 7456 # Check each spin. 7457 spin_index = 0 7458 for spin, spin_id in spin_loop(return_id=True): 7459 # Printout. 7460 print("\nSpin %s." % spin_id) 7461 7462 # Check the fitted parameters. 7463 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 7464 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 7465 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 7466 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 7467 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 7468 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 7469 7470 # Increment the spin index. 7471 spin_index += 1
7472 7473
7474 - def test_tp02_data_to_tap03(self):
7475 """Test the dispersion 'TAP03' model fitting against the 'TP02' test data.""" 7476 7477 # Fixed time variable and the models. 7478 ds.fixed = True 7479 ds.models = ['R2eff', 'TAP03'] 7480 7481 # Execute the script. 7482 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 7483 7484 # Switch back to the data pipe for the optimisation. 7485 self.interpreter.pipe.switch('TAP03 - relax_disp') 7486 7487 # The equivalent TAP03 parameters. 7488 r1rho_prime = [[10.0058156589442, 15.005818505006], [12.0766046472748, 18.076648462452]] 7489 pA = [0.775042569092891, 0.500000000229685] 7490 kex = [1235.20852748765, 2379.47085580169] 7491 delta_omega = [7.08176806468445, 5.40708372863538] 7492 chi2 = [0.0371366837083293, 0.182212857256044] 7493 7494 # Alias the spins. 7495 spin1 = cdp.mol[0].res[0].spin[0] 7496 spin2 = cdp.mol[0].res[1].spin[0] 7497 7498 # The R20 keys. 7499 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 7500 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 7501 7502 # Printout. 7503 print("\n\nOptimised parameters:\n") 7504 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 7505 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 7506 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 7507 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 7508 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 7509 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 7510 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 7511 7512 # Switch to the 'MP05' model data pipe, then check for each spin. 7513 self.interpreter.pipe.switch('TAP03 - relax_disp') 7514 spin_index = 0 7515 for spin, spin_id in spin_loop(return_id=True): 7516 # Printout. 7517 print("\nSpin %s." % spin_id) 7518 7519 # Check the fitted parameters. 7520 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 7521 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 7522 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 7523 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 7524 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 7525 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 7526 7527 # Increment the spin index. 7528 spin_index += 1
7529 7530
7531 - def test_tp02_data_to_tp02(self):
7532 """Test the relaxation dispersion 'TP02' model curve fitting to fixed time synthetic data.""" 7533 7534 # Fixed time variable. 7535 ds.fixed = True 7536 7537 # Execute the script. 7538 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 7539 7540 # The original parameters. 7541 r1rho_prime = [[10.0, 15.0], [12.0, 18.0]] 7542 pA = 0.7654321 7543 kex = 1234.56789 7544 delta_omega = [7.0, 9.0] 7545 7546 # The R20 keys. 7547 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 7548 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 7549 7550 # Switch to the 'TP02' model data pipe, then check for each spin. 7551 self.interpreter.pipe.switch('TP02 - relax_disp') 7552 spin_index = 0 7553 for spin, spin_id in spin_loop(return_id=True): 7554 # Printout. 7555 print("\nSpin %s." % spin_id) 7556 7557 # Check the fitted parameters. 7558 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 7559 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 7560 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 7561 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3) 7562 7563 # Increment the spin index. 7564 spin_index += 1
7565 7566
7568 """System test of the value.write function to write intensities for an R1rho setup. 7569 This system test is to make sure, that modifying the API for special parameters theta and w_eff does not alter the functionality value.write. 7570 7571 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 7572 """ 7573 7574 # Load the state. 7575 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 7576 self.interpreter.state.load(statefile, force=True) 7577 7578 # Set filepaths. 7579 int_filepath = ds.tmpdir+sep+'int.out' 7580 7581 # Write out the intensity parameter file. 7582 # The writing out of intensity file is to make sure the API function retains its function after modification for special parameters. 7583 self.interpreter.value.write(param='peak_intensity', file='int.out', dir=ds.tmpdir, scaling=1.0, force=True) 7584 7585 # Test the file exists. 7586 self.assert_(access(int_filepath, F_OK)) 7587 7588 # Open the files for testing. 7589 int_file = open(int_filepath, 'r') 7590 7591 # Loop over the intensity file to test values. 7592 for line in int_file: 7593 # Skip lines starting with #. 7594 if line[0] == "#": 7595 continue 7596 7597 # Split the line 7598 linesplit = line.split() 7599 7600 # Assume values 7601 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 7602 self.assertEqual(linesplit[5], "115571.4") 7603 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 7604 self.assertEqual(linesplit[5], "68377.52") 7605 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 7606 self.assertEqual(linesplit[5], "9141.689") 7607 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 7608 self.assertEqual(linesplit[5], "29123.77") 7609 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 7610 self.assertEqual(linesplit[5], "58914.94") 7611 7612 # Close files 7613 int_file.close()
7614 7615
7617 """System test of the value.write function to write return values of theta from calc_rotating_frame_params() function for an R1rho setup. 7618 7619 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 7620 """ 7621 7622 # Load the state. 7623 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 7624 self.interpreter.state.load(statefile, force=True) 7625 7626 # Set filepaths. 7627 theta_filepath = ds.tmpdir+sep+'theta.out' 7628 7629 # Write out the theta parameter file. 7630 self.interpreter.value.write(param='theta', file='theta.out', dir=ds.tmpdir, scaling=1.0, force=True) 7631 7632 # Test the file exists. 7633 self.assert_(access(theta_filepath, F_OK)) 7634 7635 # Open the files for testing. 7636 theta_file = open(theta_filepath, 'r') 7637 7638 # Loop over the theta file to test values. 7639 for line in theta_file: 7640 # Skip lines starting with #. 7641 if line[0] == "#": 7642 continue 7643 # Print lines, not including newline character. 7644 print(line[:-1]) 7645 7646 # Split the line 7647 linesplit = line.split() 7648 7649 # Assume values 7650 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 7651 self.assertNotEqual(linesplit[5], "None") 7652 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 7653 self.assertNotEqual(linesplit[5], "None") 7654 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 7655 self.assertNotEqual(linesplit[5], "None") 7656 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 7657 self.assertNotEqual(linesplit[5], "None") 7658 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 7659 self.assertNotEqual(linesplit[5], "None") 7660 7661 # Close files 7662 theta_file.close()
7663 7664
7666 """System test of the value.write function to write return values of w_eff from calc_rotating_frame_params() function for an R1rho setup. 7667 7668 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 7669 """ 7670 7671 # Load the state. 7672 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 7673 self.interpreter.state.load(statefile, force=True) 7674 7675 # Set filepaths. 7676 w_eff_filepath = ds.tmpdir+sep+'w_eff.out' 7677 7678 # Write out the w_eff parameter file. 7679 self.interpreter.value.write(param='w_eff', file='w_eff.out', dir=ds.tmpdir, scaling=1.0, force=True) 7680 7681 # Test the file exists. 7682 self.assert_(access(w_eff_filepath, F_OK)) 7683 7684 # Open the files for testing. 7685 w_eff_file = open(w_eff_filepath, 'r') 7686 7687 # Loop over the w_eff file to test values. 7688 for line in w_eff_file: 7689 # Skip lines starting with #. 7690 if line[0] == "#": 7691 continue 7692 # Print lines, not including newline character. 7693 print(line[:-1]) 7694 7695 # Split the line 7696 linesplit = line.split() 7697 7698 # Assume values 7699 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 7700 self.assertNotEqual(linesplit[5], "None") 7701 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 7702 self.assertNotEqual(linesplit[5], "None") 7703 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 7704 self.assertNotEqual(linesplit[5], "None") 7705 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 7706 self.assertNotEqual(linesplit[5], "None") 7707 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 7708 self.assertNotEqual(linesplit[5], "None") 7709 7710 # Close files 7711 w_eff_file.close()
7712 7713
7715 """System test of the auto_analysis value.write function to write theta and w_eff values for an R1rho setup. 7716 7717 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 7718 """ 7719 7720 # Load the state. 7721 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344.bz2' 7722 self.interpreter.state.load(statefile, force=True) 7723 7724 # Set pipe name, bundle and type. 7725 pipe_name = 'base pipe' 7726 pipe_bundle = 'relax_disp' 7727 pipe_type = 'relax_disp' 7728 7729 # The path to the data files. 7730 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 7731 7732 # Deselect all spins 7733 self.interpreter.deselect.all() 7734 7735 # Specify spins to be selected. 7736 select_spin_ids = [ 7737 ":13@N", 7738 ":15@N", 7739 ":16@N", 7740 ":25@N", 7741 ":26@N", 7742 ":28@N", 7743 ":39@N", 7744 ":40@N", 7745 ":41@N", 7746 ":43@N", 7747 ":44@N", 7748 ":45@N", 7749 ":49@N", 7750 ":52@N", 7751 ":53@N"] 7752 7753 # Reverse the selection for the spins. 7754 for curspin in select_spin_ids: 7755 print("Selecting spin %s"%curspin) 7756 self.interpreter.deselect.reverse(spin_id=curspin) 7757 7758 # Read the R1 data 7759 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 7760 7761 # The dispersion models. 7762 MODELS = ['R2eff'] 7763 7764 # The grid search size (the number of increments per dimension). 7765 GRID_INC = 4 7766 7767 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7768 MC_NUM = 3 7769 7770 # Model selection technique. 7771 MODSEL = 'AIC' 7772 7773 # Execute the auto-analysis (fast). 7774 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7775 OPT_FUNC_TOL = 1e-1 7776 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7777 OPT_MAX_ITERATIONS = 1000 7778 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7779 7780 # Run the analysis. 7781 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=ds.tmpdir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 7782 7783 ## Check for file creation 7784 # Set filepaths. 7785 theta_filepath = ds.tmpdir+sep+MODELS[0]+sep+'theta.out' 7786 w_eff_filepath = ds.tmpdir+sep+MODELS[0]+sep+'w_eff.out' 7787 7788 # Test the files exists. 7789 self.assert_(access(theta_filepath, F_OK)) 7790 self.assert_(access(w_eff_filepath, F_OK)) 7791 7792 # Open the files for testing. 7793 theta_file = open(theta_filepath, 'r') 7794 theta_result = [ 7795 "# Parameter description: Rotating frame tilt angle : ( theta = arctan(w_1 / Omega) ) (rad).\n", 7796 "#\n", 7797 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 7798 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7799 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7800 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7801 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7802 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7803 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7804 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7805 "None 13 L None N 1.83827367612531 None 1.79015307643158 None 2.2768687598681 None 2.08461171779445 None 2.00120623474388 None 1.92825070277699 None 1.47212860033516 None 1.12978017906854 None 1.20415336139956 None 0.901691390796334 None 0.687390207543568 None 0.455635480573046 None 0.281637123971289 None 0.138259661766539 None \n", 7806 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7807 "None 15 R None N 1.58367544790673 None 1.58127411936947 None 1.61085209029811 None 1.59731540507347 None 1.59237108385522 None 1.58834866344307 None 1.2251048782537 None 0.938142786712004 None 1.03297495592991 None 0.683284686224254 None 0.594447788256641 None 0.383528609383686 None 0.262780814059893 None 0.133469839450564 None \n", 7808 "None 16 T None N 1.40984232256624 None 1.43947245672073 None 1.10299856647417 None 1.24811470332083 None 1.30521602599932 None 1.35302443831853 None 1.07923777467974 None 0.833345927788896 None 0.934350308974616 None 0.581325254389991 None 0.543659670184793 None 0.346238480454282 None 0.251454336191817 None 0.130436714663781 None \n", 7809 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7810 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7811 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7812 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7813 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7814 "None 25 Q None N 1.81569700258844 None 1.77137827615015 None 2.23175875585624 None 2.04612705363098 None 1.9673155780155 None 1.89908711012298 None 1.44829660124856 None 1.11023386429581 None 1.18716091371256 None 0.877306975624962 None 0.677790118853413 None 0.447932002242236 None 0.279785379050945 None 0.137802891887767 None \n", 7815 "None 26 Q None N 1.61128821168674 None 1.60374392042003 None 1.69619923953765 None 1.65403989292986 None 1.63856717205868 None 1.62595755714564 None 1.24977859227795 None 0.956353494917591 None 1.04972090035774 None 0.702164059520172 None 0.603227813742091 None 0.390116910781037 None 0.264658552037535 None 0.133960994297096 None \n", 7816 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7817 "None 28 Q None N 1.65182797011356 None 1.63676707684161 None 1.81830827892972 None 1.7365089711986 None 1.70601955220877 None 1.68102938663686 None 1.28685736157369 None 0.984047498595701 None 1.0749792109454 None 0.731585685663053 None 0.616577997665602 None 0.400219205533665 None 0.267471993812649 None 0.134690869499646 None \n", 7818 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7819 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7820 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7821 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7822 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7823 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7824 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7825 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7826 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7827 "None 39 L None N 1.76426439181176 None 1.72885318885161 None 2.11826300085737 None 1.95430201082222 None 1.88794717058464 None 1.83172922971397 None 1.39549951193417 None 1.06783946148624 None 1.14997013232702 None 0.826128785942585 None 0.657105386950171 None 0.431542911580536 None 0.275725736430539 None 0.136791385554619 None \n", 7828 "None 40 M None N 1.5521741199158 None 1.55564594516135 None 1.51290906497298 None 1.53245929150759 None 1.53960430408466 None 1.54541832596591 None 1.19750223001929 None 0.917959090226757 None 1.01428385962747 None 0.662779584695967 None 0.584708929219264 None 0.376271266885303 None 0.260671619214194 None 0.132914250767089 None \n", 7829 "None 41 A None N 1.68339451828261 None 1.66252964414082 None 1.90911961276946 None 1.79959323497326 None 1.75801925517113 None 1.72370710837265 None 1.31646868936419 None 1.00647189763597 None 1.09525348649914 None 0.75605702767542 None 0.627395557358039 None 0.408481831044309 None 0.269716174238842 None 0.135267948387412 None \n", 7830 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7831 "None 43 F None N 1.58506597154432 None 1.58240542750303 None 1.61517196062351 None 1.60017740004898 None 1.59469990835425 None 1.59024353162528 None 1.22633651794829 None 0.939047922181951 None 1.03380990731605 None 0.684214484755514 None 0.594884298549546 None 0.383855128702894 None 0.262874695048502 None 0.13349447283116 None \n", 7832 "None 44 I None N 1.57575471961837 None 1.57483015671791 None 1.58622388390755 None 1.58100758841935 None 1.57910319967536 None 1.57755415552211 None 1.21811077066835 None 0.933010299763027 None 1.02823520295828 None 0.67802911457195 None 0.591972285081647 None 0.381678892926696 None 0.262247347241724 None 0.133329708422379 None \n", 7833 "None 45 K None N 1.77147501495754 None 1.73479633022489 None 2.13509660780385 None 1.96751045408372 None 1.89924480319914 None 1.84124387452692 None 1.40277881643715 None 1.07361367582571 None 1.15506365550891 None 0.832963505534767 None 0.659913187081268 None 0.433751178249555 None 0.276282572106685 None 0.13693095791902 None \n", 7834 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7835 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7836 "None 49 A None N 2.00297059962685 None 1.92978318052058 None 2.53305709323468 None 2.33052197276846 None 2.22870514722639 None 2.13201782446864 None 1.6587904412969 None 1.29333162369472 None 1.34311052758116 None 1.12559033900783 None 0.770195063841652 None 0.524846264860003 None 0.296857751274362 None 0.141908833673671 None \n", 7837 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7838 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7839 "None 52 V None N 1.82421571143794 None 1.77845404105203 None 2.24910726268822 None 2.06078232916932 None 1.98017451806059 None 1.91012195713554 None 1.45724107606646 None 1.11753869321304 None 1.19352234944057 None 0.886361068343012 None 0.681372607920812 None 0.450799407357501 None 0.280478735779163 None 0.137974257665877 None \n", 7840 "None 53 A None N 2.05019708195234 None 1.97089957318506 None 2.58789168363698 None 2.39027806684801 None 2.28731354878582 None 2.1872118539319 None 1.7165709935896 None 1.34832362477229 None 1.38879751095815 None 1.2085314357749 None 0.799450059125864 None 0.550583841461621 None 0.30195492609136 None 0.143090604877102 None \n", 7841 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7842 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7843 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7844 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7845 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 7846 ] 7847 # Check the created theta file. 7848 lines = theta_file.readlines() 7849 for i in range(len(lines)): 7850 # Test lines starting with # 7851 if theta_result[i][0] == "#": 7852 self.assertEqual(theta_result[i], lines[i]) 7853 # If the line is equal each other, make a line comparison. This should catch lines with None values. 7854 if theta_result[i] == lines[i]: 7855 self.assertEqual(theta_result[i], lines[i]) 7856 # If the line is not equal each other, make a slower comparison of values. 7857 else: 7858 # Print lines if they don't match. To help find differences. 7859 print(theta_result[i]) 7860 print(lines[i]) 7861 7862 # First test first 62 characters containing spin information 7863 self.assertEqual(theta_result[i][:62], lines[i][:62]) 7864 7865 # Make a string split after 62 characters. Select each second element, so None values are skipped. 7866 theta_result_s = theta_result[i][62:].split()[::2] 7867 print(theta_result_s ) 7868 lines_s = lines[i][62:].split()[::2] 7869 print(lines_s) 7870 # Loop over the value elements 7871 for j in range(len(lines_s)): 7872 print(theta_result_s[j], lines_s[j]) 7873 # Assume a precision to digits. 7874 self.assertAlmostEqual(float(theta_result_s[j]), float(lines_s[j]), 14) 7875 7876 # Close file 7877 theta_file.close() 7878 7879 w_eff_file = open(w_eff_filepath, 'r') 7880 w_eff_result = [ 7881 "# Parameter description: Effective field in rotating frame : ( w_eff = sqrt(Omega^2 + w_1^2) ) (rad.s^-1).\n", 7882 "#\n", 7883 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 7884 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7885 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7886 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7887 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7888 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7889 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7890 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7891 "None 13 L None N 8737.12883908829 None 10612.1226552258 None 3558.93734069587 None 4698.27194621826 None 5534.46153956037 None 6599.82570817753 None 8467.62674839481 None 9318.00441649087 None 11095.2662520767 None 6412.33580591254 None 13279.9803044242 None 11430.254637056 None 30318.7268264644 None 61141.1080046448 None \n", 7892 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7893 "None 15 R None N 8427.14155005377 None 10358.3995676635 None 2710.22680763322 None 4093.04942975722 None 5030.86065069262 None 6183.60685459024 None 8956.28403254202 None 10448.6627754369 None 12060.4428066937 None 7966.64282975241 None 15045.8392092364 None 13441.3586252373 None 32438.4764809909 None 63321.5201471181 None \n", 7894 "None 16 T None N 8536.7818857229 None 10447.792678989 None 3034.01707453628 None 4314.2767521567 None 5212.43600885913 None 6332.21319855067 None 9558.14311447582 None 11384.2336494604 None 12879.4604966293 None 9159.34604475399 None 16290.1746838959 None 14821.0200530829 None 33866.5933527757 None 64785.3205696403 None \n", 7895 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7896 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7897 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7898 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7899 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7900 "None 25 Q None N 8685.60895531182 None 10569.7459677762 None 3430.51272680396 None 4601.75421490393 None 5452.76508815826 None 6531.46859076009 None 8490.06475886501 None 9406.58372902508 None 11169.7602637607 None 6540.38696356753 None 13437.7348017798 None 11613.1632549021 None 30514.0741594726 None 61342.4792156782 None \n", 7901 "None 26 Q None N 8433.35533683544 None 10363.4554631194 None 2729.48656005151 None 4105.82770792005 None 5041.26238350827 None 6192.07245313098 None 8880.08366342131 None 10312.6868786802 None 11942.8320576165 None 7787.44854491812 None 14853.4987024375 None 13225.7048162038 None 32213.6690023282 None 63090.7407990801 None \n", 7902 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7903 "None 28 Q None N 8454.18308422202 None 10380.4112885894 None 2793.17494362899 None 4148.43953208179 None 5076.02756135055 None 6220.40920270029 None 8777.91538040813 None 10118.8737706315 None 11775.8792998529 None 7528.90766101027 None 14572.4015102398 None 12909.211050939 None 31882.8171856889 None 62750.9120842199 None \n", 7904 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7905 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7906 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7907 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7908 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7909 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7910 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7911 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7912 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7913 "None 39 L None N 8586.6405431352 None 10488.5710521378 None 3171.59430904777 None 4412.11227722123 None 5293.69814015286 None 6399.27143075725 None 8557.58926327909 None 9617.45773774313 None 11347.9169998729 None 6840.20010813426 None 13795.1250622375 None 12024.9041436853 None 30951.651485352 None 61793.2130509111 None \n", 7914 "None 40 M None N 8427.90394711227 None 10359.0198301036 None 2712.59646573568 None 4094.61889210019 None 5032.13762965554 None 6184.6458240746 None 9049.68452800053 None 10607.7913029633 None 12198.5639821231 None 8174.23271685285 None 15266.4924700447 None 13687.9010998756 None 32694.9043143038 None 63584.6371927381 None \n", 7915 "None 41 A None N 8480.14299737436 None 10401.5648897003 None 2870.79081440785 None 4201.09083283266 None 5119.14733505123 None 6255.64579267482 None 8706.50768957471 None 9972.71017314947 None 11650.5225246067 None 7331.28858930568 None 14354.1616183112 None 12662.3378547029 None 31623.9195264738 None 62484.8290612112 None \n", 7916 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7917 "None 43 F None N 8427.30062786474 None 10358.5289868368 None 2710.7214015056 None 4093.37694357637 None 5031.12711571215 None 6183.82364721878 None 8952.31975962078 None 10441.7375680915 None 12054.4435931163 None 7957.55789315654 None 15036.1316712316 None 13430.4914212645 None 32427.1596037519 None 63309.9050677925 None \n", 7918 "None 44 I None N 8426.54623319716 None 10357.9152496503 None 2708.3751705368 None 4091.82359712664 None 5029.86337809029 None 6182.79552045043 None 8979.12144335458 None 10488.2688526334 None 12094.7720286018 None 8018.51779989075 None 15101.1843990883 None 13503.2816173444 None 32502.9389163062 None 63387.6763306952 None \n", 7919 "None 45 K None N 8599.01176345321 None 10498.7013581079 None 3204.93649737055 None 4436.14046641897 None 5313.74138343704 None 6415.86177652694 None 8546.79665373249 None 9587.16245449134 None 11322.2529042385 None 6797.53838612575 None 13745.1536613763 None 11967.5433300612 None 30890.8603419261 None 61730.6213936947 None \n", 7920 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7921 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7922 "None 49 A None N 9279.63849130869 None 11063.0654625247 None 4737.11992391463 None 5643.40583860235 None 6356.45614406507 None 7302.87406141381 None 8459.17105047661 None 8761.54554569995 None 10632.2343488142 None 5572.92782399155 None 12102.1714908775 None 10037.6988885228 None 28806.6916858172 None 59579.0348769179 None \n", 7923 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7924 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7925 "None 52 V None N 8704.45610117774 None 10585.2389163429 None 3477.9549539207 None 4637.22923167743 None 5482.73656118686 None 6556.5108895527 None 8481.06470969555 None 9372.86414918436 None 11141.3782476763 None 6491.79686536093 None 13378.2843939736 None 11544.3205736882 None 30440.62308788 None 61266.7742546508 None \n", 7926 "None 53 A None N 9497.02860450276 None 11246.0339326126 None 5149.96766581255 None 5994.15475647208 None 6669.81232845336 None 7577.19152075731 None 8516.77431951689 None 8639.36099840319 None 10531.7750336522 None 5378.79193153767 None 11752.8060152439 None 9613.59939949642 None 28334.9153747994 None 59090.2988815445 None \n", 7927 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7928 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7929 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7930 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 7931 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 7932 ] 7933 # Check the created w_eff file. 7934 lines = w_eff_file.readlines() 7935 for i in range(len(lines)): 7936 # Test lines starting with # 7937 if w_eff_result[i][0] == "#": 7938 self.assertEqual(w_eff_result[i], lines[i]) 7939 # If the line is equal each other, make a line comparison. This should catch lines with None values. 7940 if w_eff_result[i] == lines[i]: 7941 self.assertEqual(w_eff_result[i], lines[i]) 7942 # If the line is not equal each other, make a slower comparison of values. 7943 else: 7944 # Print lines if they don't match. To help find differences. 7945 print(w_eff_result[i]) 7946 print(lines[i]) 7947 7948 # First test first 62 characters containing spin information 7949 self.assertEqual(w_eff_result[i][:62], lines[i][:62]) 7950 7951 # Make a string split after 62 characters. Select each second element, so None values are skipped. 7952 w_eff_result_s = w_eff_result[i][62:].split()[::2] 7953 print(w_eff_result_s ) 7954 lines_s = lines[i][62:].split()[::2] 7955 print(lines_s) 7956 # Loop over the value elements 7957 for j in range(len(lines_s)): 7958 print(w_eff_result_s[j], lines_s[j]) 7959 # Assume a precision to digits. 7960 self.assertAlmostEqual(float(w_eff_result_s[j]), float(lines_s[j]), 14) 7961 7962 # Close file 7963 w_eff_file.close()
7964 7965
7967 """Test the user function for estimating R2eff errors from exponential curve fitting, and compare it with Monte-Carlo simulations. 7968 7969 This follows Task 7822. 7970 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 7971 7972 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 7973 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 7974 """ 7975 7976 # Load the data. 7977 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 7978 7979 # Set pipe name, bundle and type. 7980 pipe_name = 'base pipe' 7981 pipe_bundle = 'relax_disp' 7982 pipe_type = 'relax_disp' 7983 7984 # Create the data pipe. 7985 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 7986 7987 file = data_path + '1_setup_r1rho_GUI.py' 7988 self.interpreter.script(file=file, dir=None) 7989 7990 # Deselect all spins. 7991 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 7992 7993 # Select one spin. 7994 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7995 7996 # Set the model. 7997 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 7998 7999 # Check if intensity errors have already been calculated. 8000 check_intensity_errors() 8001 8002 # Do a grid search. 8003 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 8004 8005 # Set algorithm. 8006 min_algor = 'Newton' 8007 constraints = True 8008 if constraints: 8009 min_options = ('%s'%(min_algor),) 8010 #min_algor = 'Log barrier' 8011 min_algor = 'Method of Multipliers' 8012 scaling_matrix = assemble_scaling_matrix(scaling=True) 8013 8014 # Collect spins 8015 all_spin_ids = [] 8016 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8017 all_spin_ids.append(spin_id) 8018 8019 spins = spin_ids_to_containers(all_spin_ids[:1]) 8020 8021 # Get constraints 8022 A, b = linear_constraints(spins=spins, scaling_matrix=scaling_matrix[0]) 8023 else: 8024 min_options = () 8025 A, b = None, None 8026 min_options = () 8027 sim_boot = 200 8028 scaling_list = [1.0, 1.0] 8029 8030 # Minimise. 8031 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints, verbosity=1) 8032 8033 # Loop over old err attributes. 8034 err_attr_list = ['r2eff_err', 'i0_err'] 8035 8036 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8037 # Loop over old err attributes. 8038 for err_attr in err_attr_list: 8039 if hasattr(cur_spin, err_attr): 8040 delattr(cur_spin, err_attr) 8041 8042 # Collect the estimation data from boot. 8043 my_dic = {} 8044 param_key_list = [] 8045 est_keys = [] 8046 est_key = '-2' 8047 est_keys.append(est_key) 8048 spin_id_list = [] 8049 8050 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8051 # Add key to dic. 8052 my_dic[spin_id] = {} 8053 8054 # Add key for estimate. 8055 my_dic[spin_id][est_key] = {} 8056 8057 # Add spin key to list. 8058 spin_id_list.append(spin_id) 8059 8060 # Generate spin string. 8061 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 8062 8063 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 8064 # Generate the param_key. 8065 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 8066 8067 # Append key. 8068 param_key_list.append(param_key) 8069 8070 # Add key to dic. 8071 my_dic[spin_id][est_key][param_key] = {} 8072 8073 values = [] 8074 errors = [] 8075 times = [] 8076 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 8077 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 8078 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 8079 times.append(time) 8080 8081 # Convert to numpy array. 8082 values = asarray(values) 8083 errors = asarray(errors) 8084 times = asarray(times) 8085 8086 r2eff = getattr(cur_spin, 'r2eff')[param_key] 8087 i0 = getattr(cur_spin, 'i0')[param_key] 8088 8089 R_m_sim_l = [] 8090 I0_m_sim_l = [] 8091 for j in range(sim_boot): 8092 if j in range(0, 100000, 100): 8093 print("Simulation %i"%j) 8094 # Start minimisation. 8095 8096 # Produce errors 8097 I_err = [] 8098 for j, error in enumerate(errors): 8099 I_error = gauss(values[j], error) 8100 I_err.append(I_error) 8101 # Convert to numpy array. 8102 I_err = asarray(I_err) 8103 8104 x0 = [r2eff, i0] 8105 setup(num_params=len(x0), num_times=len(times), values=I_err, sd=errors, relax_times=times, scaling_matrix=scaling_list) 8106 8107 # Ref input. 8108 #def generic_minimise(func=None, dfunc=None, d2func=None, args=(), x0=None, min_algor=None, min_options=None, func_tol=1e-25, grad_tol=None, maxiter=1e6, A=None, b=None, l=None, u=None, c=None, dc=None, d2c=None, print_flag=0, print_prefix="", full_output=False): 8109 # l=l, u=u, c=c, dc=dc, d2c=d2c 8110 # l: Lower bound constraint vector (l <= x <= u). 8111 # u: Upper bound constraint vector (l <= x <= u). 8112 # c: User supplied constraint function. 8113 # dc: User supplied constraint gradient function. 8114 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=func, dfunc=dfunc, d2func=d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, A=A, b=b, full_output=True, print_flag=0) 8115 8116 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 8117 R_m_sim_l.append(R_m_sim_j) 8118 I0_m_sim_l.append(I0_m_sim_j) 8119 8120 # Get stats on distribution. 8121 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 8122 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 8123 my_dic[spin_id][est_key][param_key]['r2eff_err'] = sigma_R_sim 8124 my_dic[spin_id][est_key][param_key]['i0_err'] = sigma_I0_sim 8125 8126 # Estimate R2eff errors. 8127 self.interpreter.relax_disp.r2eff_err_estimate() 8128 8129 est_key = '-1' 8130 est_keys.append(est_key) 8131 8132 # Collect data. 8133 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8134 # Add key for estimate. 8135 my_dic[spin_id][est_key] = {} 8136 8137 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 8138 # Generate the param_key. 8139 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 8140 8141 # Add key to dic. 8142 my_dic[spin_id][est_key][param_key] = {} 8143 8144 # Get the value. 8145 # Loop over err attributes. 8146 for err_attr in err_attr_list: 8147 if hasattr(cur_spin, err_attr): 8148 get_err_attr = getattr(cur_spin, err_attr)[param_key] 8149 else: 8150 get_err_attr = 0.0 8151 8152 # Save to dic. 8153 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 8154 8155 8156 # Make Carlo Simulations number 8157 mc_number_list = list(range(0, 1000, 250)) 8158 8159 sim_attr_list = ['chi2_sim', 'f_count_sim', 'g_count_sim', 'h_count_sim', 'i0_sim', 'iter_sim', 'peak_intensity_sim', 'r2eff_sim', 'select_sim', 'warning_sim'] 8160 8161 # Loop over the Monte Carlo simulations: 8162 for number in mc_number_list: 8163 # First delete old simulations. 8164 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8165 # Loop over old err attributes. 8166 for err_attr in err_attr_list: 8167 if hasattr(cur_spin, err_attr): 8168 delattr(cur_spin, err_attr) 8169 8170 # Loop over the simulated attributes. 8171 for sim_attr in sim_attr_list: 8172 if hasattr(cur_spin, sim_attr): 8173 delattr(cur_spin, sim_attr) 8174 8175 self.interpreter.monte_carlo.setup(number=number) 8176 self.interpreter.monte_carlo.create_data() 8177 self.interpreter.monte_carlo.initial_values() 8178 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints) 8179 self.interpreter.eliminate() 8180 self.interpreter.monte_carlo.error_analysis() 8181 8182 est_key = '%i'%number 8183 est_keys.append(est_key) 8184 8185 # Collect data. 8186 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8187 # Add key for estimate. 8188 my_dic[spin_id][est_key] = {} 8189 8190 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 8191 # Generate the param_key. 8192 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 8193 8194 # Add key to dic. 8195 my_dic[spin_id][est_key][param_key] = {} 8196 8197 # Get the value. 8198 # Loop over err attributes. 8199 for err_attr in err_attr_list: 8200 if hasattr(cur_spin, err_attr): 8201 get_err_attr = getattr(cur_spin, err_attr)[param_key] 8202 else: 8203 get_err_attr = 0.0 8204 8205 # Save to dic. 8206 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 8207 8208 # Set what to extract. 8209 err_attr = err_attr_list[0] 8210 8211 # Define list with text. 8212 text_list = [] 8213 8214 # Now loop through the data. 8215 for spin_id in spin_id_list: 8216 for est_key in est_keys: 8217 # Define list to pickup data. 8218 r2eff_err_list = [] 8219 8220 for param_key in param_key_list: 8221 # Get the value. 8222 r2eff_err = my_dic[spin_id][est_key][param_key][err_attr] 8223 8224 # Add to list. 8225 r2eff_err_list.append(r2eff_err) 8226 8227 # Sum the list 8228 sum_array = sum(array(r2eff_err_list)) 8229 8230 # Join floats to string. 8231 r2eff_err_str = " ".join(format(x, "2.3f") for x in r2eff_err_list) 8232 8233 # Define print string. 8234 text = "%8s %s sum= %2.3f" % (est_key, r2eff_err_str, sum_array) 8235 text_list.append(text) 8236 8237 8238 # Now print. 8239 filepath = NamedTemporaryFile(delete=False).name 8240 # Open the files for testing. 8241 w_file = open(filepath, 'w') 8242 8243 print("Printing the estimated R2eff error as function of estimation from Co-variance and number of Monte-Carlo simulations.") 8244 8245 for text in text_list: 8246 # Print. 8247 print(text) 8248 8249 # Write to file. 8250 w_file.write(text+"\n") 8251 8252 # Close files 8253 w_file.close() 8254 8255 print("Filepath is: %s"%filepath) 8256 print("Start 'gnuplot' and write:") 8257 print("set term dumb") 8258 print("plot '%s' using 1:17 title 'R2eff error as function of MC number' w linespoints "%filepath)
8259 8260
8261 - def verify_r1rho_kjaergaard_missing_r1(self, models=None, result_dir_name=None, r2eff_estimate=None):
8262 """Verification of test_r1rho_kjaergaard_missing_r1.""" 8263 8264 # Check the kex value of residue 52 8265 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 8266 8267 # Print results for each model. 8268 print("\n\n################") 8269 print("Printing results") 8270 print("################\n") 8271 for model in models: 8272 # Skip R2eff model. 8273 if model == MODEL_R2EFF: 8274 continue 8275 8276 # Switch to pipe. 8277 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 8278 print("\nModel: %s" % (model)) 8279 8280 # Loop over the spins. 8281 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8282 # Generate spin string. 8283 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 8284 8285 # Loop over the parameters. 8286 print("Optimised parameters for spin: %s" % (spin_string)) 8287 for param in cur_spin.params + ['chi2']: 8288 # Get the value. 8289 if param in ['r1', 'r2']: 8290 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 8291 # Generate the R20 key. 8292 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 8293 8294 # Get the value. 8295 value = getattr(cur_spin, param)[r20_key] 8296 8297 # Print value. 8298 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 8299 8300 # Compare values. 8301 if spin_id == ':52@N': 8302 if param == 'r1': 8303 if model == MODEL_NOREX: 8304 if r2eff_estimate == 'direct': 8305 self.assertAlmostEqual(value, 1.46138805) 8306 elif r2eff_estimate == 'MC2000': 8307 self.assertAlmostEqual(value, 1.46328102) 8308 elif r2eff_estimate == 'chi2_pyt': 8309 self.assertAlmostEqual(value, 1.43820629) 8310 elif model == MODEL_DPL94: 8311 if r2eff_estimate == 'direct': 8312 self.assertAlmostEqual(value, 1.44845742) 8313 elif r2eff_estimate == 'MC2000': 8314 self.assertAlmostEqual(value, 1.45019848) 8315 elif r2eff_estimate == 'chi2_pyt': 8316 self.assertAlmostEqual(value, 1.44666512) 8317 elif model == MODEL_TP02: 8318 if r2eff_estimate == 'direct': 8319 self.assertAlmostEqual(value, 1.54354392) 8320 elif r2eff_estimate == 'MC2000': 8321 self.assertAlmostEqual(value, 1.54352369) 8322 elif r2eff_estimate == 'chi2_pyt': 8323 self.assertAlmostEqual(value, 1.55964020) 8324 elif model == MODEL_TAP03: 8325 if r2eff_estimate == 'direct': 8326 self.assertAlmostEqual(value, 1.54356410) 8327 elif r2eff_estimate == 'MC2000': 8328 self.assertAlmostEqual(value, 1.54354367) 8329 elif r2eff_estimate == 'chi2_pyt': 8330 self.assertAlmostEqual(value, 1.55967157) 8331 elif model == MODEL_MP05: 8332 if r2eff_estimate == 'direct': 8333 self.assertAlmostEqual(value, 1.54356416) 8334 elif r2eff_estimate == 'MC2000': 8335 self.assertAlmostEqual(value, 1.54354372) 8336 elif r2eff_estimate == 'chi2_pyt': 8337 self.assertAlmostEqual(value, 1.55967163) 8338 elif model == MODEL_NS_R1RHO_2SITE: 8339 if r2eff_estimate == 'direct': 8340 self.assertAlmostEqual(value, 1.41359221, 5) 8341 elif r2eff_estimate == 'MC2000': 8342 self.assertAlmostEqual(value, 1.41321968, 5) 8343 elif r2eff_estimate == 'chi2_pyt': 8344 self.assertAlmostEqual(value, 1.36303129, 5) 8345 8346 elif param == 'r2': 8347 if model == MODEL_NOREX: 8348 if r2eff_estimate == 'direct': 8349 self.assertAlmostEqual(value, 11.48392439) 8350 elif r2eff_estimate == 'MC2000': 8351 self.assertAlmostEqual(value, 11.48040934) 8352 elif r2eff_estimate == 'chi2_pyt': 8353 self.assertAlmostEqual(value, 11.47224488) 8354 elif model == MODEL_DPL94: 8355 if r2eff_estimate == 'direct': 8356 self.assertAlmostEqual(value, 10.15688372, 6) 8357 elif r2eff_estimate == 'MC2000': 8358 self.assertAlmostEqual(value, 10.16304887, 6) 8359 elif r2eff_estimate == 'chi2_pyt': 8360 self.assertAlmostEqual(value, 9.20037797, 6) 8361 elif model == MODEL_TP02: 8362 if r2eff_estimate == 'direct': 8363 self.assertAlmostEqual(value, 9.72654896, 6) 8364 elif r2eff_estimate == 'MC2000': 8365 self.assertAlmostEqual(value, 9.72772726, 6) 8366 elif r2eff_estimate == 'chi2_pyt': 8367 self.assertAlmostEqual(value, 9.53948340, 6) 8368 elif model == MODEL_TAP03: 8369 if r2eff_estimate == 'direct': 8370 self.assertAlmostEqual(value, 9.72641887, 6) 8371 elif r2eff_estimate == 'MC2000': 8372 self.assertAlmostEqual(value, 9.72759374, 6) 8373 elif r2eff_estimate == 'chi2_pyt': 8374 self.assertAlmostEqual(value, 9.53926913, 6) 8375 elif model == MODEL_MP05: 8376 if r2eff_estimate == 'direct': 8377 self.assertAlmostEqual(value, 9.72641723, 6) 8378 elif r2eff_estimate == 'MC2000': 8379 self.assertAlmostEqual(value, 9.72759220, 6) 8380 elif r2eff_estimate == 'chi2_pyt': 8381 self.assertAlmostEqual(value, 9.53926778, 6) 8382 elif model == MODEL_NS_R1RHO_2SITE: 8383 if r2eff_estimate == 'direct': 8384 self.assertAlmostEqual(value, 9.34531535, 5) 8385 elif r2eff_estimate == 'MC2000': 8386 self.assertAlmostEqual(value, 9.34602793, 5) 8387 elif r2eff_estimate == 'chi2_pyt': 8388 self.assertAlmostEqual(value, 9.17631409, 5) 8389 8390 # For all other parameters. 8391 else: 8392 # Get the value. 8393 value = getattr(cur_spin, param) 8394 8395 # Print value. 8396 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 8397 8398 # Compare values. 8399 if spin_id == ':52@N': 8400 if param == 'phi_ex': 8401 if model == MODEL_DPL94: 8402 if r2eff_estimate == 'direct': 8403 self.assertAlmostEqual(value, 0.07599563) 8404 elif r2eff_estimate == 'MC2000': 8405 self.assertAlmostEqual(value, 0.07561937) 8406 elif r2eff_estimate == 'chi2_pyt': 8407 self.assertAlmostEqual(value, 0.12946061) 8408 8409 elif param == 'pA': 8410 if model == MODEL_TP02: 8411 if r2eff_estimate == 'direct': 8412 self.assertAlmostEqual(value, 0.88827040) 8413 elif r2eff_estimate == 'MC2000': 8414 self.assertAlmostEqual(value, 0.88807487) 8415 elif r2eff_estimate == 'chi2_pyt': 8416 self.assertAlmostEqual(value, 0.87746233) 8417 elif model == MODEL_TAP03: 8418 if r2eff_estimate == 'direct': 8419 self.assertAlmostEqual(value, 0.88828922) 8420 elif r2eff_estimate == 'MC2000': 8421 self.assertAlmostEqual(value, 0.88809318) 8422 elif r2eff_estimate == 'chi2_pyt': 8423 self.assertAlmostEqual(value, 0.87747558) 8424 elif model == MODEL_MP05: 8425 if r2eff_estimate == 'direct': 8426 self.assertAlmostEqual(value, 0.88828924, 6) 8427 elif r2eff_estimate == 'MC2000': 8428 self.assertAlmostEqual(value, 0.88809321) 8429 elif r2eff_estimate == 'chi2_pyt': 8430 self.assertAlmostEqual(value, 0.87747562) 8431 elif model == MODEL_NS_R1RHO_2SITE: 8432 if r2eff_estimate == 'direct': 8433 self.assertAlmostEqual(value, 0.94504369, 6) 8434 elif r2eff_estimate == 'MC2000': 8435 self.assertAlmostEqual(value, 0.94496541, 6) 8436 elif r2eff_estimate == 'chi2_pyt': 8437 self.assertAlmostEqual(value, 0.92084707, 6) 8438 8439 elif param == 'dw': 8440 if model == MODEL_TP02: 8441 if r2eff_estimate == 'direct': 8442 self.assertAlmostEqual(value, 1.08875840, 6) 8443 elif r2eff_estimate == 'MC2000': 8444 self.assertAlmostEqual(value, 1.08765638, 6) 8445 elif r2eff_estimate == 'chi2_pyt': 8446 self.assertAlmostEqual(value, 1.09753230, 6) 8447 elif model == MODEL_TAP03: 8448 if r2eff_estimate == 'direct': 8449 self.assertAlmostEqual(value, 1.08837238, 6) 8450 elif r2eff_estimate == 'MC2000': 8451 self.assertAlmostEqual(value, 1.08726698, 6) 8452 elif r2eff_estimate == 'chi2_pyt': 8453 self.assertAlmostEqual(value, 1.09708821, 6) 8454 elif model == MODEL_MP05: 8455 if r2eff_estimate == 'direct': 8456 self.assertAlmostEqual(value, 1.08837241, 6) 8457 elif r2eff_estimate == 'MC2000': 8458 self.assertAlmostEqual(value, 1.08726706, 6) 8459 elif r2eff_estimate == 'chi2_pyt': 8460 self.assertAlmostEqual(value, 1.09708832, 6) 8461 elif model == MODEL_NS_R1RHO_2SITE: 8462 if r2eff_estimate == 'direct': 8463 self.assertAlmostEqual(value, 1.56001812, 5) 8464 elif r2eff_estimate == 'MC2000': 8465 self.assertAlmostEqual(value, 1.55833321, 5) 8466 elif r2eff_estimate == 'chi2_pyt': 8467 self.assertAlmostEqual(value, 1.36406712, 5) 8468 8469 elif param == 'kex': 8470 if model == MODEL_DPL94: 8471 if r2eff_estimate == 'direct': 8472 self.assertAlmostEqual(value/1e5, 4460.43711569/1e5, 7) 8473 elif r2eff_estimate == 'MC2000': 8474 self.assertAlmostEqual(value/1e5, 4419.03917195/1e5, 7) 8475 elif r2eff_estimate == 'chi2_pyt': 8476 self.assertAlmostEqual(value/1e5, 6790.22736344/1e5, 7) 8477 elif model == MODEL_TP02: 8478 if r2eff_estimate == 'direct': 8479 self.assertAlmostEqual(value/1e5, 4921.28602757/1e5, 7) 8480 elif r2eff_estimate == 'MC2000': 8481 self.assertAlmostEqual(value/1e5, 4904.70144883/1e5, 7) 8482 elif r2eff_estimate == 'chi2_pyt': 8483 self.assertAlmostEqual(value/1e5, 5146.20306591/1e5, 7) 8484 elif model == MODEL_TAP03: 8485 if r2eff_estimate == 'direct': 8486 self.assertAlmostEqual(value/1e5, 4926.42963491/1e5, 7) 8487 elif r2eff_estimate == 'MC2000': 8488 self.assertAlmostEqual(value/1e5, 4909.86877150/1e5, 7) 8489 elif r2eff_estimate == 'chi2_pyt': 8490 self.assertAlmostEqual(value/1e5, 5152.51105814/1e5, 7) 8491 elif model == MODEL_MP05: 8492 if r2eff_estimate == 'direct': 8493 self.assertAlmostEqual(value/1e5, 4926.44236315/1e5, 7) 8494 elif r2eff_estimate == 'MC2000': 8495 self.assertAlmostEqual(value/1e5, 4909.88110195/1e5, 7) 8496 elif r2eff_estimate == 'chi2_pyt': 8497 self.assertAlmostEqual(value/1e5, 5152.52097111/1e5, 7) 8498 elif model == MODEL_NS_R1RHO_2SITE: 8499 if r2eff_estimate == 'direct': 8500 self.assertAlmostEqual(value/1e5, 5628.66061488/1e5, 7) 8501 elif r2eff_estimate == 'MC2000': 8502 self.assertAlmostEqual(value/1e5, 5610.20221435/1e5, 6) 8503 elif r2eff_estimate == 'chi2_pyt': 8504 self.assertAlmostEqual(value/1e5, 5643.34067090/1e5, 6) 8505 8506 elif param == 'chi2': 8507 if model == MODEL_NOREX: 8508 if r2eff_estimate == 'direct': 8509 self.assertAlmostEqual(value, 848.42016907, 5) 8510 elif r2eff_estimate == 'MC2000': 8511 self.assertAlmostEqual(value, 3363.95829122, 5) 8512 elif r2eff_estimate == 'chi2_pyt': 8513 self.assertAlmostEqual(value, 5976.49946726, 5) 8514 elif model == MODEL_DPL94: 8515 if r2eff_estimate == 'direct': 8516 self.assertAlmostEqual(value, 179.47041241) 8517 elif r2eff_estimate == 'MC2000': 8518 self.assertAlmostEqual(value, 710.24767560) 8519 elif r2eff_estimate == 'chi2_pyt': 8520 self.assertAlmostEqual(value, 612.72616697, 5) 8521 elif model == MODEL_TP02: 8522 if r2eff_estimate == 'direct': 8523 self.assertAlmostEqual(value, 29.33882530, 6) 8524 elif r2eff_estimate == 'MC2000': 8525 self.assertAlmostEqual(value, 114.47142772, 6) 8526 elif r2eff_estimate == 'chi2_pyt': 8527 self.assertAlmostEqual(value, 250.50838162, 5) 8528 elif model == MODEL_TAP03: 8529 if r2eff_estimate == 'direct': 8530 self.assertAlmostEqual(value, 29.29050673, 6) 8531 elif r2eff_estimate == 'MC2000': 8532 self.assertAlmostEqual(value, 114.27987534) 8533 elif r2eff_estimate == 'chi2_pyt': 8534 self.assertAlmostEqual(value, 250.04050719, 5) 8535 elif model == MODEL_MP05: 8536 if r2eff_estimate == 'direct': 8537 self.assertAlmostEqual(value, 29.29054301, 6) 8538 elif r2eff_estimate == 'MC2000': 8539 self.assertAlmostEqual(value, 114.28002272) 8540 elif r2eff_estimate == 'chi2_pyt': 8541 self.assertAlmostEqual(value, 250.04077478, 5) 8542 elif model == MODEL_NS_R1RHO_2SITE: 8543 if r2eff_estimate == 'direct': 8544 self.assertAlmostEqual(value, 34.44010543, 6) 8545 elif r2eff_estimate == 'MC2000': 8546 self.assertAlmostEqual(value, 134.14368365) 8547 elif r2eff_estimate == 'chi2_pyt': 8548 self.assertAlmostEqual(value, 278.55121388, 5) 8549 8550 8551 # Print the final pipe. 8552 model = 'final' 8553 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 8554 print("\nFinal pipe") 8555 8556 # Loop over the spins. 8557 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8558 # Generate spin string. 8559 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 8560 8561 # Loop over the parameters. 8562 print("Optimised model for spin: %s" % (spin_string)) 8563 param = 'model' 8564 8565 # Get the value. 8566 value = getattr(cur_spin, param) 8567 print("%-10s %-6s %-6s %6s" % ("Parameter:", param, "Value:", value)) 8568 8569 8570 ### Now check some of the written out files. 8571 file_names = ['r1rho_prime', 'r1'] 8572 8573 for file_name_i in file_names: 8574 8575 # Make the file name. 8576 file_name = "%s.out" % file_name_i 8577 8578 # Get the file path. 8579 file_path = get_file_path(file_name, result_dir_name + sep + model) 8580 8581 # Test the file exists. 8582 print("Testing file access to: %s"%file_path) 8583 self.assert_(access(file_path, F_OK)) 8584 8585 # Now open, and compare content, line by line. 8586 file_prod = open(file_path) 8587 lines_prod = file_prod.readlines() 8588 file_prod.close() 8589 8590 # Loop over the lines. 8591 for i, line in enumerate(lines_prod): 8592 # Make the string test 8593 line_split = line.split() 8594 8595 # Continue for comment lines. 8596 if line_split[0] == "#": 8597 print(line), 8598 continue 8599 8600 # Assign the split of the line. 8601 mol_name, res_num, res_name, spin_num, spin_name, val, sd_error = line_split 8602 print(mol_name, res_num, res_name, spin_num, spin_name, val, sd_error) 8603 8604 if res_num == '52': 8605 # Assert that the value is not None. 8606 self.assertNotEqual(val, 'None')
8607